for the typewriter effect you could add rounding to string_copy so you can increment in decimals for better control of the typing speed. textPart = string_copy(text[page], 1, ceil(charCount); All in all great tutorial
This is by far the best tutorial I've ever seen. Great job explaining everything and making it easy to understand. I love that the video is packed with info and you don't linger at any moment. Thank you!
Really good tutorial and I was able to cheat a little and simply widen my NPC's collision mask so that you can initiate the dialog without having to be on top of NPC. I know there are more 'real' solutions for this if you browse the comments, but due to my game's style it was just so fast n easy. Thanks again.
I've recently read some of your suggestions in the comment section. Thanks to you i could edit easily my script (graphically), so now the textbox is fixed in a specific point of the screen when a character speaks. There are only 2 things i have to fix. 1) With the collision on, i can't see the script if i'm not pressing the key that moves the character towards the CPU. I guess i need to add a "range" or change something in place_meeting function (i think the coordinates), so even if my character isn't fully attached to the CPU character i can stil see the script. 2) During the script the character can move around, and the script disappears. I'd like my character can't move while a CPU is speaking until it's done. I imagine there is a way to set the step moving to 0. Maybe something like you did with myTextbox or creator variables, bur i admit i don't know well how to do that. I'm sorry i'm just a beginner. I prefer drawings and sprites to codes, but i need to learn something and how to use Gamemaker Studio 2.
dude this is so cool! thank you so much for making these tutorials I'm still kinda new to GMS2 so the core mechanics of it are a struggle for me, and I was trying to figure out how to add dialog for ages but I just couldn't get it, but this is perfect for what I wanted, and you make it so easy to follow along to now I know how the core of it works I can expand on it and do all sorts I managed to set up some alarms on my NPC object so that between every 5 to 10 seconds it'll pop up with dialog box, have pages and stuff, and then reset itself basically changing it from keyboard input to an alarm and then if the player talks to the NPC it interrupts it and switches to the player triggered interaction instead and won't rerun until the player has stopped talking to them so like shop keepers can shout out their wares and stuff in a market without needing player interaction and stuff like that
Been following tutorials on text dialogs for GMS 1.4 and each one was more complicated than the other; using ds_list and scripts and stuff. And here I'm, finally finding the easiest and best explained tutorial ever, which is meant for GMS 2 LOL (works for 1.4 btw, just don't use the instance_create_layer function). Thanks!!
omg, missed turning text[page] to textpart at 7:34 and spent forever trying to fix it because I kept getting errors. Love this tutorial though, by far the best one I have found, and works perfectly with my preexisting code for my game! thank you!
works pretty well!! I was using different sprites, and all I had to do was change the space key (because I was already using it for a jump key), and I worked! Full Game here I come!
Hey, great video! I can't believe how easy text boxes are in GM2 compared to GM1. I remember slaving away to do all the maths to wrap text and all that and to think that it can all be done in one line of code is absolute madness! You might already know this but I thought a neat tip for you (or others) is if you just put all of the stuff that's in the Create Event into the instance's Creation Code instead then you only need one NPC object that you can put multiple of and just change what they're named or what they say in the Creation Code instead so you don't have to make a separate object for each NPC.
Thank you! Yes, this is a great tip!! The only reservation I'd have about this is just that it can be a bit confusing for beginners -- and it might just be easier to organise your project/assets if you keep them as separate objects. But if you can do this, it's a great way to streamline code/objects -- especially in simple games.
Very true! Heck, it took me a good minute to figure out if Game Maker Studio 2 even still had Creation Code because I had trouble finding it, so I can definitely understand it not being a beginner's method.
thank you so much for the tutorial! with little bit of alterations I could make it launch on click and release of the mouse button so you don't accidentally speak to people haha
Timestamps for reference: This seems to be a very basic system. 0:54 Using an array to store the strings in the create event of Susan 2:15 page = 0 on Susan create event 3:06 Prevention of textbox creation upon touching obj_Susan; now we will check if space is pressed [assuming we are already colliding with obj_Susan] 3:26 What happens if textbox page out of range? (Game crashes.) 3:51 Check in the space key press whether page +1 is less than length of array. If it is no longer less (aka equal to array length) and we hit space again, then instance_destroy(myTextbox); 5:04 Resetting myTextbox variable in Susan so she may create another one; this will be necessary in the textbox itself too (idk why) and we will generalise across all NPCs 5:28 Get the creator of the textbox [set a variable in the create event] 5:52 Set creator variable during when spacebar is pressed and when touching obj_susan to "self". 6:05 Problem: textbox goes back to first line 6:43 Solution: use of a really short alarm - in obj_susan, when the alarm is done, it sets myTextbox = noone. 7:17 Typewriter effect [charCount += 1 in the draw event] 9:40 Resetting charCount to 0 when pressing space. Limiting charCount to be < total length of string (string_length(text[page])). If charCount < string length, then charCount += 1. Note: *a fellow commenter also suggested "textPart = string_copy(text[page], 1, ceil(charCount)); 10:50 Adding the name of the NPC 11:30 myTextbox.name is set to myName variable from the Create event (aka myTextbox.name = "Susan") 11:50 Putting the main text below 12:23 Buffer space (aka padding) 12:51 Need to ensure text moves to next line nicely when it hits the right side (set boxWidth to be minus 2 * xBuffer. We had shifted the box to the right by adding to the x value by xBuffer. Try to make a diagram to visualise why we need to move it by 2 * xBuffer [it's like chopping the right side twice].) NOTE: Refer to 21:17, because you'll need the original width for drawing a border. 13:29 Adding padding to the name too, and centralising the name 14:03 Fixing the off-centredness --> draw_set_halign(fa_center), then setting it back otherwise all the text after that will follow the fa_center setting 15:08 Creating another NPC by duplication and changing the variable values 16:35 Using inheritance 19:12 Skip function 20:33 Clean Up, Border Adding 21:17 put the minus 2*xBuffer directly in draw text, changing name colour, etc.
I dont know if this is still usefull for anyone, but for everyone who had problems with the space between lines when the textbox was activated for the first time, this is how I fixed it: instead of draw_text_ext(x + xBuffer, y + stringHeight + yBuffer, textPart, stringHeight, boxWidth); I removed "stringHeight" from "y + stringHeight + yBuffer" and replaced the second "stringHeight" with a number (any number would do, I used 11), to get: draw_text_ext(x + xBuffer, y + stringHeight + yBuffer, textPart, 11, boxWidth); This seemed to work for me. Hope this helps :)
Hey, sorry just looking for some help... When setting up the Alarm so that the instance is destroyed when I press space when I reach the limit of pages, I'm getting an error message in game. Do you have any advice on this? Thanks:)
@@mysticalnat Perhaps rewatch 3:35 to 7:13. Check if you copied these steps very precisely (this is where the “destroy textbox” was added to the game). Did you put in a comment that says -> nothing should be done when reaching the limit of pages? I hope this helps! If not, could you perhaps explain what the error says?
Hi! Thank you so much for the tutorial. I wanted to ask one question. Right now, if you leave a long dialogue running (without skipping using "x" or "enter"), the last bit of word draws on the screen briefly on the right before wrapping around and drawing again below the current line. Since we're using the built-in draw_text_ext method, is there a way to prevent this behavior (besides manipulating the dialogue itself)? I'd love to get rid of the "drawing briefly before realizing that it went over the width limit" behavior, and just make it wrap around right away... Thank you so much!
Hey FriendlyCosmonaut, thanks for the great tutorials! I am enjoying this tutorial very much. I am currently at the step of adding an alarm to destroy the dialogue instance and successfully got this to work. However, when I try to interact with the NPC again it will not create it again. I’m just seeing if you have any idea as to why Some things to note: None of the objects are persistent, it won’t create the dialogue again until I leave the room and return, I stepped through the debugger and for whatever reason it isn’t updating the “myTextbox” variable back to “no one” after it destroys it which is what is likely causing the issue. It’s very strange and I’ve banged my head on the wall for quite a bit at this point. Thank you in advance!
Yeah as you say it sounds like myTextbox isn't being reset. Perhaps the problem is that the "creator" variable isn't being set correctly, so it isn't having the correct object running the code to reset it? Check in the debug if it's being updated from whatever the default value is. If that doesn't work, could you send me some screenshots of your code (where it's resetting the myTextbox variable, and also the code for creating the textbox). Or you can just e-mail me your project at friendlycosmonaut@gmail.com.
Hey, just wanted to say thank you and let you know I figured it out. The problem was (I should've also mentioned this initially -_-) I am using my own alarm system because I have delta_time implemented into my project. Long story short, my own alarm being contained to the "action key/space bar" IF statement in objTextBox prevented it from actually counting down and triggering the "myTextbox = noone" (since it wouldn't count down unless I was pressing the "action key". I moved this logic to a different event in the objTalkerParent and it seems to work. Thanks again for all you do I love your tutorials and they help me immensely. You are a great teacher.
Hey! Excellent video, thank you so much. Just a quick question: how would you make it so that the word would start on the next line (at the end of a line) instead of beginning to write itself then jumping down to the next line? When playing, this comes out very distracting for me and I would love help fixing it, because I can't figure it out myself ahaha. Thanks! Example of what I'm talking about if it's unclear: If I want to write "He went that way, sir! I saw Timothy heading downstairs." ...the game would write "He went that way, sir! I saw Timot" and then would erase "Timot" and bump it down to the next line, so it reads: Line 1: "He went that way, sir! I saw" Line 2: "Timothy heading downstairs." How would I make "Timothy" (and every other word) check that it is too long to fit on that line before it is written and bump itself down?
This is so good, thank you! Question: how do you make a noise play when a letter appears (similar to how it happens in Paper Mario and Undertale)? Thank you!
My problem is that the second time you interact with the NPC and the text box plays, it's different...? I changed the stringHeight because i wanted more space between the lines of text, but only applies it to the second time i let the textbox play. The first time I interact, the stringHeight is not correct and the x and yBuffers are off by a few pixels. I'm really unsure how to fix this.
I ran into an issue at the end, where the text was too high up the first time i interacted with the object, but the second time it was in the right place. Is there a way to fix this?
Nice job!, but just some advice in case you didnt know, you should arrange your arrays starting with the highest number, so that it allocates the whole amount instead of reallocating data for each entry, (Saves space)
Anyone know how to fix the problem of a word being made, then skipping to the next line as it's being spelled out? Like say you have a 10 letter word as the last word in a line, it will be on that line as the first 5 letters are ticked onto the screen, but when it gets too long for the right side of the box, the whole word jumps to the next line to finish being spelled out. It's a small thing but it annoys me...
Thanks a bunch! I really wanted to add some text boxes to give my digital games project a bit of a boost in quality and you definitely delivered! Now I wanna make all the trees talk just to show off haha! Now... How to make the textbox appear in the bottom left or middle...
my text box is appearing behind the sprites. is it a layering issue or is it a code issue? and if i wanted to move the textbox to the top of the screen whilst keeping the player still, how would i go about that?
Cheers! Haha yeah -- if you're just starting out, I wouldn't jump into textboxes just yet. I'd probably recommend starting with things like movement and collisions.
FriendlyCosmonaut My thoughts are that the use of instances is what most people find difficult. Tbh i know movement collision basic AI and have done some mini projects , but still found this a little bit advanced . Ill try watching 2 or 3 times ...
Your system is neat. Even tho i would like to see how can you trigger events when certain page is on the screen. I already found some solutions but i doubt i did it right. My main problem is that i can't put events on the 0 page because 0 page will trigger events even after i leave dialogue screen. Any suggestions?
thank you for the incredible tutorial! just out of curiosity, i was fiddling around with the position of the box. i had it follow an object that would always stay in the bottom area of the camera view for the game. this way, i had the box always travel to this object, which would make the text box appear at the bottom of the screen. but now, even if i return it to the original position, the text seems to jump to a lower y coordinate after re-engaging the text box. any ideas on how to help? if not thank you for the incredible tutorial either way. edit: it had to do with the string length variable, it only works if you dont move the box. at least for me.
I love your tutorial, but there's an oversight. If you move away from the NPC while talking to them, the NPC deletes itself, and the game crashes after you are done with the dialog... this is due to having the "instance_destroy(); " right after checking with if the space bar is pressed on obj_parent_talker removing this line of code fixes the issue, and leaves the textbox in place until you are finished reading! Thank you so much this guide!
Thank you! Ah, that line is supposed to delete the TEXTBOX when you move away from the NPC, not the NPC. So it should say "with(myTextbox) instance_destroy();" instead of just "instance_destroy();".
Great tutorial thanks a lot! :) Any tips on creating some kind of "conversation" system based on this? For example, changing the name of the character (alternating Susan and Bob for example) and changing the position of the text box (depending on the character who is speaking). Hope my question makes sense! Thank you :)
I'll likely be making a video on this in the future (for the farming RPG series)! But for now, I'll tell you the logic of what you could do. We could make our "text" a bit more complex: instead of just a 1D array, we could use a 2D array, so we could specify who is saying it. So for example: //First line text[0,0] = "Hey there."; text[0,1] = obj_bob; //Second line text[1,0] = "Oh hello, Bob!"; text[1,1] = obj_susan; And so on. And then when we spawn the textbox, you could have it access the array variable for which "object" should be saying it, and move the textbox relative to that object.
Hey FriendlyCosmonaut! i'm not sure if you still comment here but firstly, thank you so much for these tutorials they are absolutely amazing! :D I just wanted to find out if you could help me with this (i'm new at this so might be jumping in to deep water here). I'm trying to make it so when you talk to a character it changes from a "normal" state (character moves around) to a "talking" state (character can only press space to talk/disables directional movement control). It works perfectly if you talk to the first child of the obj_parent_talker but it doesn't seem to work on the 2nd child. I also noticed that when you talk the to 1st child the myTextbox calls back (i think the instance number which is 100078) however when you talk to the 2nd child it comes back as -4. Do problems arise when you have more than 1 child? I hope that makes sense.. thanks again!!
Hi! This is a wonderful video and I definitely love it! I was curious if you had or knew another video which could be followed to implement an achievement system where the text a character was saying would change after the achievement was gained/item was given. Thanks!
Ah, unfortunately not. I'll be looking to do something similar in upcoming tutorials in the Farming RPG series on dialogue. For now, if it's something that will occur immediately after an NPC has been spoken to, you could just have a variable change when the textbox gets destroyed?
Hey! your video is the best! It helps me alot with the RPG game that i am now making, but still i got one question i want to give the textbox a specifike place like at the bottom of my gamescreen. is there a way to do it? sorry im a huge amateur :/
Thank you, I'm glad it helped. No problem - I would suggest putting everything into the "Draw GUI" event (literally copy everything from the draw event and put it in the draw GUI), and then everywhere we put "x,y", replace those with specific co-ordinates that you want to draw the textbox. The Draw GUI event will draw the textbox at those specific co-ordinates on the screen regardless of views (it is not affected by it). Here is a bit of info from the docs on the Draw GUI: "The Draw Gui sub-event type falls under the Draw Event category and is specifically designed for drawing GUI (Graphical User Interface) elements that are not affected by the view scale or rotation. This means that you can have an instance draw all the elements for your HUD without having to base all the positioning of the elements on the the instance position within the room or the position of the current view. When drawing in these event it is important that you understand that the draw coordinates do not change even when views are active and (0,0) is always the top left hand corner of either the application surface or the display (see the note at the bottom of this section), and the default width and height are 1:1 with the application surface. " Note: If you have scaled your game up, the text in the draw GUI will not be scaled -- so you'll probably have to make the font larger.
Another good thing to note is if you're using views, you'll want to put this line at the start of your Draw GUI event: display_set_gui_size(camera_get_view_width(view_camera[0]),camera_get_view_height(view_camera[0])); This is because the GUI uses it's own resolution, separate from the view's resolution.
The first tutorial was great but I can't get past the first part of this one. I'm not getting any errors and as far as I can tell I have the same code as you, but my vk check doesn't seem to work with any button I assign and it stays on the first page of text. Please leave the code written out to check ours against. I liked the first video so much.
i'm no expert but here's my guess: in the step event of your npc, you should have a line called myTextbox.text = mytext; or something like that below the instance_create_layer line. I think you can put stuff like "if variable = 1 {myTextbox.text = mytext} else {myTextbox.text=adifferentarrayofdialogue}"
or! you could make mytext an array full of arrays! for example: myTextbox.text=mytext -> if variable {myTextbox.text=mytext[1];} else {myTextbox.text=mytext[0]; and in create you can assign your dialogue like: mytext[0]=["1", "2", "3"]; mytext[1]=["4", "5', "etc"];
I have a question that has been holding me back for a long time. Is there a way to make the text wrap the word BEFORE it starts typing the word? For Instance "Hello my name is reallylongnamedman." When it types it would say, get halfway through his name, then jarringly jump down to the next line. Is there a way to make it KNOW it won't fit and just start it on the new line? Or do I have to manually add the line breaks at that point? If you could answer this it would help out a lot!
Yes, there is a way! Well, there's many. Since I'm going to do another video on this in the future, for now I'm just going to point you towards a great tutorial by heartbeast on this topic. The system will be a little different to ours, but the solution will be perfectly adaptable. Just note that in GMS2, the "#" symbol to go to a new line is now " ". The relevant part starts here: ua-cam.com/video/8kL4kfWiLsg/v-deo.htmlm59s
I have a couple of issues -- I used the -bbox_bottom as a depth system and all of my objects are above the text box, I tried a lot of tutorial and different method and couldn't get any to work so Idk how to change it -- how do I change the thickness and color of the rectangle? -- how do I set the box place relative to the viewport? edit: had another really dumb issue that I solved lmao
Your dialogue is awesome and easy to understand, I quite learned a lot of things from it and I thank you so much for it. I have one question if you don't mind and that's : "How can I create "obj_textbox" using the views ?", because in the tutorial it was created in a room with no views. I did tried to use view_xview and view_ywiew instead of x and y in the drawing event (for text and sprites), but it didn't show up in screen.
You mean so that the textbox will appear relative to the views? The "view_xview and view_yview" are for GMS1. The corresponding functions in GMS2 are camera_get_view_x() and camera_get_view_y(). You also have to tell it what camera to get the x and y position of, so if you're using view_camera[0], you'd put: camera_get_view_x(view_camera[0]). Note: This will get you the position of the top left corner of the view, so you'll want to add to both values to get it somewhere reasonable on the screen.
Some bug fixes i noted for anyone needing without searching much! Anyone can comment down if they know how to fix more efficiently than me (im still a noob afterall),while also ill be editing any new fix i know (Edit now i know how to make it work with viewports :) ) 1- how to make the textbox centered/in a different place than origining from the character? i went to the draw event in obj_textbox,in the draw_sprite part,i changed the x and y values to custom numbers of where i would want it to be made, example = draw_sprite(Sprite3,0,6,511),i just changed the x and y to 6 and 511(it can be any number,thats just mine) Do the same thing in the draw_text_ext Xs and Ys, pro tip: make it slightly different than the box's X and Y if you want Something more centered like the text's X being a little less than the box's X THEN copy allll the code in the Draw event of the obj_textbox and move it to the Draw Gui event,so it can work with viewports! Its just a matter of changing the Xs and Ys to custom ones 2- how to make the player stop/pause while theres a textbox? make a object called obj_pause it doesnt need a sprite or any code at all,it just need to exist go to your player events,step event put this code(that im putting bellow)above all the lines of movement,like before any coding that changes the player x and y if instance_exists (obj_pause){ (whatever variable for the movement keys you made,right or right_key whatever) right_key = 0 left_key = 0 } note: right_key,left_key whatever are my variables to the movement of the character,if your variables have a diff name like example "right = keyboard_check_pressed(vk_right)", put the variable "right" inside the "if instance_exists(obj_pause)" code,just so you dont get lost if yours are different then,go to obj_textbox, parent and put obj_pause as its parent what happens? whenever a instance of obj_textbox is created,a instance of obj_pause is created,meaning you cant move while the instance of textbox exists! and since the textbox is destroyed after the pages are done,the obj_pause is also destroyed! 3- text lines appearing squished togheter for the first time the textbox is made,and getting fixed the second time its made honestly i dont know how to fix it yet but a good idea is to just make the first textbox's text being short and not being long enough to have 2 lines of text, so once all the other ones are made they are already fixed
Hey @friendlycosmonaut Great work. A quick question! What sort of logic would I use to make my text boxes spawn in a standard, bottom centre location of my current view, rather then spawning from the NPC we are currently interacting with?
You can use "Draw GUI" rather than the "Draw" function and set the y value to (your view width - the height of the text box) and x to 0 Hope this helps!
Thanks so much for the great tutorial! I've encountered a bit of a strange problem where the dialogue system works perfectly the first time the player talks to an NPC, but every subsequent time dialogue is prompted the text is written at a lower y position on the screen and stays in this new position consistently. I've been looking over the code for hours now and can't seem to find the issue, so any help would be greatly appreciated!
@@ASSORTEDJELLIES I couldn't figure out a solution so I ended up scrapping my code and following her new textbox tutorial in the farming rpg series where I got it to work. Hope you're able to figure it out!
guys, i have problem. trying to index a variable which is not an array at gml_Object_obj_textbox_Draw_0 (line 10) - draw_text_ext(x,y, text[page], stringHeight, boxVigth ); wtf?
Haha possibly one day, but it may be a while. But I'd wager someone has done a tutorial on this topic before so you might have more luck searching around.
I actually figured it out on my own :) Instead of using a sprite I just used draw_rectangle and calculated the size it should be based on the current text so that it grows with the text (up to a max width I've set).
Hmm interesting how the ext seems to do the same work as pre-formatting the text. It's hard to tell in the example, though, does this function automatically wrap text while printing out or do the first few letters appear at the top before dropping to the bottom? I'm guessing the latter since you aren't running a format function on the text but only wrapping it live during the draw, so I wouldn't imagine gamemaker automatically knows which words to return on. And text length? I'm presuming if you used a text of sufficient length, it would probably print off the end rather than doing some kind of scroll effect. Which I would imagine are the reasons to still pre-format text for maximum flexibility. Do you plan to do a more advanced text tutorial in the future? I also had a question regarding a more advanced feature of text boxes that I kind of got used to when I started scripting for Morrowind. In that engine, you could use a % sign to indicate a variable such as %PCName. This will be a valuable function in my current project as well, but everything I've read to date indicates that all functions to pull script or variable names out of strings are gone. Do you know how something like this might be set up in gamemaker? Will I just have to come up with a text processing script that assembles strings from a signal symbol like this one and compare their values to a list of possible variables?
Yeah, the first few letters appear at the top -- it's only wrapping the text by the letters. It's a pretty simple function, and won't do anything like scrolling. Definitely programming it and formatting it yourself would allow you to be more flexible. I definitely would like to do an advanced tutorial in the future -- where we basically do everything ourselves, so we eg. wrap the text by words, add sound effects, and throw in effects (colours, moving letters, etc). To be honest though, I can't say when that would happen, as there's a lot I want to do in this series first -- I'd say it's months off. There's a function called string_replace(str, substr, newstr), which replaces a part of a string with another. But if you wanted other kinds of functionality, I believe you're correct - you may have to write the scripts yourself. For example you could increment a position variable, and check each character of a string using string_char_at to see if it returns the first letter of the word you're looking for, and if it does, check the NEXT character and see if it is equal to the second letter of the word you want, etc. If it finds the word, your script could then return true, and go on and do other things -- delete the word, insert a new one, etc.
Wow, thanks. That is so much easier than I feared it would be. And the best part is, I can run it once while formatting my text and adjust the width afterward, so I don't have to worry about someone using a really long name like MisterMcSnarkyPants. I'm not too worried about pulling non-text variables out of a string for now, but I'll just have to dig a little deeper if that becomes a concern. Now to figure out the scrolling action. Can't say that I blame you for wanting to finish the series first--but I can't wait to see the advanced version!
Very nice video! But i am a bit confused: You are defining the myText array in obj_susan. How can the obj_textbox know this array? Is it because of the line "myTextbox.text = myText"? Does this line "transfer" the array to obj_textbox?
Yes, this is exactly right. The variable "myText[0]" is a specific entry of the array, but just "myText" represents the entire array. So we have indeed transferred the whole array with "myTextbox.text = myText".
Wonderful video! The code works beautifully, except for one tiny snag; if you press the key to skip text fast enough (space in your case) the text will start looping over itself infinitely, locking the player in the textbox event. Do you have any ideas for how to stop this?
Is there a way to change a certain word's color? Like a keyword within the dialogue that needs be like a different color besides white. Anyways, insanely great tutorial on dialogue, we're using this dialogue system in our game :D
THANK YOU, hope you know that you're still helping people even after 6 years
Showing your steps, how you first establish and then optimize something, is crucial to me. It has clicked with me like nothing else.
You make some pretty darn good tutorials!
Haha cheers :)!
for the typewriter effect you could add rounding to string_copy so you can increment in decimals for better control of the typing speed.
textPart = string_copy(text[page], 1, ceil(charCount);
All in all great tutorial
Ooh, this is a great idea!!
This is by far the best tutorial I've ever seen. Great job explaining everything and making it easy to understand. I love that the video is packed with info and you don't linger at any moment. Thank you!
The best gamemaker tutorial that i find on youtube, holy molly.
Hello again from 2020, FriendlyCosmonaut. Thank you for part 2 of this great tutorial! I got a lot out of it!
hello from 2021, same thing lol
In a week I'm making things I never thought would be possible for me, you're a really great teacher. Thank you so much!
2:47 on days like these, kid's like you... [insert megalovania]
*You are gonna have a great tutorial
lol
@@itsshiep3732 SAME
This was extremely useful and easy compared to the other videos I have seen THANK YOU!!!
Wow, this is actually one of the best tuts I have ever seen on this. You make things sound so simple. Thanks so so much.
Really good tutorial and I was able to cheat a little and simply widen my NPC's collision mask so that you can initiate the dialog without having to be on top of NPC. I know there are more 'real' solutions for this if you browse the comments, but due to my game's style it was just so fast n easy. Thanks again.
Thank you for these tutorials! I'm new with GameMaker Studio 2 so i'm glad your videos explain well the procedures.
I've recently read some of your suggestions in the comment section. Thanks to you i could edit easily my script (graphically), so now the textbox is fixed in a specific point of the screen when a character speaks.
There are only 2 things i have to fix.
1) With the collision on, i can't see the script if i'm not pressing the key that moves the character towards the CPU.
I guess i need to add a "range" or change something in place_meeting function (i think the coordinates), so even if my character isn't fully attached to the CPU character i can stil see the script.
2) During the script the character can move around, and the script disappears.
I'd like my character can't move while a CPU is speaking until it's done.
I imagine there is a way to set the step moving to 0. Maybe something like you did with myTextbox or creator variables, bur i admit i don't know well how to do that.
I'm sorry i'm just a beginner. I prefer drawings and sprites to codes, but i need to learn something and how to use Gamemaker Studio 2.
dude this is so cool! thank you so much for making these tutorials
I'm still kinda new to GMS2 so the core mechanics of it are a struggle for me, and I was trying to figure out how to add dialog for ages but I just couldn't get it, but this is perfect for what I wanted, and you make it so easy to follow along to
now I know how the core of it works I can expand on it and do all sorts
I managed to set up some alarms on my NPC object so that between every 5 to 10 seconds it'll pop up with dialog box, have pages and stuff, and then reset itself
basically changing it from keyboard input to an alarm
and then if the player talks to the NPC it interrupts it and switches to the player triggered interaction instead and won't rerun until the player has stopped talking to them
so like shop keepers can shout out their wares and stuff in a market without needing player interaction and stuff like that
Thanks so much! I'm really glad it helped.
Been following tutorials on text dialogs for GMS 1.4 and each one was more complicated than the other; using ds_list and scripts and stuff. And here I'm, finally finding the easiest and best explained tutorial ever, which is meant for GMS 2 LOL (works for 1.4 btw, just don't use the instance_create_layer function). Thanks!!
omg, missed turning text[page] to textpart at 7:34 and spent forever trying to fix it because I kept getting errors. Love this tutorial though, by far the best one I have found, and works perfectly with my preexisting code for my game! thank you!
I think I'm doing the same somewhere between 0:00 - 3:00 she goes too fast ;_; I don't know where I've gone wrong
I'm really enjoying the simple and clear explinations of your video's.
I watched every tutorial about dialog system using gamemaker, only with your tutorial i could make it. Thanks!!
Mind blowing moment when you highlighted multiple lines of code and just pressed tab like a madlad....
More great content!! Thank you and PLEASE keep posting.
Thank you! Yes sorry it's been a while -- I'm nearly back from holidays :)
works pretty well!! I was using different sprites, and all I had to do was change the space key (because I was already using it for a jump key), and I worked! Full Game here I come!
You're videos are so clear and concise! Thank you so much for sharing your logics!
Your*
Hey, great video! I can't believe how easy text boxes are in GM2 compared to GM1. I remember slaving away to do all the maths to wrap text and all that and to think that it can all be done in one line of code is absolute madness!
You might already know this but I thought a neat tip for you (or others) is if you just put all of the stuff that's in the Create Event into the instance's Creation Code instead then you only need one NPC object that you can put multiple of and just change what they're named or what they say in the Creation Code instead so you don't have to make a separate object for each NPC.
Thank you! Yes, this is a great tip!! The only reservation I'd have about this is just that it can be a bit confusing for beginners -- and it might just be easier to organise your project/assets if you keep them as separate objects. But if you can do this, it's a great way to streamline code/objects -- especially in simple games.
Very true! Heck, it took me a good minute to figure out if Game Maker Studio 2 even still had Creation Code because I had trouble finding it, so I can definitely understand it not being a beginner's method.
Thanks Kieran for this nice tip :)
these are way better than others ive seen, thanks very much!!
Your tutorials are fantastic. Thanks for making them.
Thank you for this tutorial. Everything was explained very well, and it helped a lot!
thank you so much for the tutorial! with little bit of alterations I could make it launch on click and release of the mouse button so you don't accidentally speak to people haha
This was so amazing thank you for good information on textbox systems
Thanks a bunch, Susan! Great tutorial!
The best teacher ever for non fluents in english like me :v
Bob and Susan. A better love story than Twilight.
Timestamps for reference:
This seems to be a very basic system.
0:54 Using an array to store the strings in the create event of Susan
2:15 page = 0 on Susan create event
3:06 Prevention of textbox creation upon touching obj_Susan; now we will check if space is pressed [assuming we are already colliding with obj_Susan]
3:26 What happens if textbox page out of range? (Game crashes.)
3:51 Check in the space key press whether page +1 is less than length of array. If it is no longer less (aka equal to array length) and we hit space again, then instance_destroy(myTextbox);
5:04 Resetting myTextbox variable in Susan so she may create another one; this will be necessary in the textbox itself too (idk why) and we will generalise across all NPCs
5:28 Get the creator of the textbox [set a variable in the create event]
5:52 Set creator variable during when spacebar is pressed and when touching obj_susan to "self".
6:05 Problem: textbox goes back to first line
6:43 Solution: use of a really short alarm - in obj_susan, when the alarm is done, it sets myTextbox = noone.
7:17 Typewriter effect [charCount += 1 in the draw event]
9:40 Resetting charCount to 0 when pressing space. Limiting charCount to be < total length of string (string_length(text[page])). If charCount < string length, then charCount += 1.
Note: *a fellow commenter also suggested "textPart = string_copy(text[page], 1, ceil(charCount));
10:50 Adding the name of the NPC
11:30 myTextbox.name is set to myName variable from the Create event (aka myTextbox.name = "Susan")
11:50 Putting the main text below
12:23 Buffer space (aka padding)
12:51 Need to ensure text moves to next line nicely when it hits the right side (set boxWidth to be minus 2 * xBuffer. We had shifted the box to the right by adding to the x value by xBuffer. Try to make a diagram to visualise why we need to move it by 2 * xBuffer [it's like chopping the right side twice].) NOTE: Refer to 21:17, because you'll need the original width for drawing a border.
13:29 Adding padding to the name too, and centralising the name
14:03 Fixing the off-centredness --> draw_set_halign(fa_center), then setting it back otherwise all the text after that will follow the fa_center setting
15:08 Creating another NPC by duplication and changing the variable values
16:35 Using inheritance
19:12 Skip function
20:33 Clean Up, Border Adding
21:17 put the minus 2*xBuffer directly in draw text, changing name colour, etc.
2:47 I feel i'm gonna have a great tutorial
I dont know if this is still usefull for anyone, but for everyone who had problems with the space between lines when the textbox was activated for the first time, this is how I fixed it:
instead of
draw_text_ext(x + xBuffer, y + stringHeight + yBuffer, textPart, stringHeight, boxWidth);
I removed "stringHeight" from "y + stringHeight + yBuffer" and replaced the second "stringHeight" with a number (any number would do, I used 11), to get:
draw_text_ext(x + xBuffer, y + stringHeight + yBuffer, textPart, 11, boxWidth);
This seemed to work for me. Hope this helps :)
You are GOD!!!!!! Thanks for help
Hey, sorry just looking for some help... When setting up the Alarm so that the instance is destroyed when I press space when I reach the limit of pages, I'm getting an error message in game. Do you have any advice on this? Thanks:)
@@mysticalnat Perhaps rewatch 3:35 to 7:13. Check if you copied these steps very precisely (this is where the “destroy textbox” was added to the game). Did you put in a comment that says -> nothing should be done when reaching the limit of pages?
I hope this helps! If not, could you perhaps explain what the error says?
Lovely little system. Thanks for making this.
thanks for all the videos you make. the only other gml videos that are as good as your tutorials are for gml 1.4
what about text teleporting? Like, if you have a long word and it gets to the edge of the box, but it jumps as it is drawn letter by letter?
Create a second box.
Hi! Thank you so much for the tutorial. I wanted to ask one question. Right now, if you leave a long dialogue running (without skipping using "x" or "enter"), the last bit of word draws on the screen briefly on the right before wrapping around and drawing again below the current line. Since we're using the built-in draw_text_ext method, is there a way to prevent this behavior (besides manipulating the dialogue itself)? I'd love to get rid of the "drawing briefly before realizing that it went over the width limit" behavior, and just make it wrap around right away... Thank you so much!
thank you this help me i hope your day is great c:
This is just brilliant, thank you so much!
Seriously awesome tutorial.
This was great, thanks for sharing your knowledge
'name' is some inbuilt variable now but this is super helpful anyways thank you !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thank you a lot for this tutorial ! Really helped me.
thank you so much. god darn good tutorino right here.
Hey FriendlyCosmonaut, thanks for the great tutorials! I am enjoying this tutorial very much. I am currently at the step of adding an alarm to destroy the dialogue instance and successfully got this to work. However, when I try to interact with the NPC again it will not create it again. I’m just seeing if you have any idea as to why
Some things to note: None of the objects are persistent, it won’t create the dialogue again until I leave the room and return, I stepped through the debugger and for whatever reason it isn’t updating the “myTextbox” variable back to “no one” after it destroys it which is what is likely causing the issue. It’s very strange and I’ve banged my head on the wall for quite a bit at this point. Thank you in advance!
Yeah as you say it sounds like myTextbox isn't being reset. Perhaps the problem is that the "creator" variable isn't being set correctly, so it isn't having the correct object running the code to reset it? Check in the debug if it's being updated from whatever the default value is.
If that doesn't work, could you send me some screenshots of your code (where it's resetting the myTextbox variable, and also the code for creating the textbox). Or you can just e-mail me your project at friendlycosmonaut@gmail.com.
Hey, just wanted to say thank you and let you know I figured it out. The problem was (I should've also mentioned this initially -_-) I am using my own alarm system because I have delta_time implemented into my project. Long story short, my own alarm being contained to the "action key/space bar" IF statement in objTextBox prevented it from actually counting down and triggering the "myTextbox = noone" (since it wouldn't count down unless I was pressing the "action key". I moved this logic to a different event in the objTalkerParent and it seems to work. Thanks again for all you do I love your tutorials and they help me immensely. You are a great teacher.
Ahh, wonderful job! Debugging is fun, hey? And thank you :)
Thanks a lot, your tutorial help me a lot
It would be nice to see a nine slice effect for the textbox that scale with the text in the textbox :)
Hey! Excellent video, thank you so much. Just a quick question: how would you make it so that the word would start on the next line (at the end of a line) instead of beginning to write itself then jumping down to the next line? When playing, this comes out very distracting for me and I would love help fixing it, because I can't figure it out myself ahaha. Thanks!
Example of what I'm talking about if it's unclear:
If I want to write "He went that way, sir! I saw Timothy heading downstairs."
...the game would write "He went that way, sir! I saw Timot" and then would erase "Timot" and bump it down to the next line, so it reads:
Line 1: "He went that way, sir! I saw"
Line 2: "Timothy heading downstairs."
How would I make "Timothy" (and every other word) check that it is too long to fit on that line before it is written and bump itself down?
I had an issue with that as well and the only thing that helped really was changing the xbuffer variable. I can't figure it out at the moment.
I hope I am not too late, I made it jump to another line by adding
before each word that would cross the limit. worked for me. Good luck.
@@aymaneelasslouj2066 just watch her farming RPG videos to fix this, she makes a wrapping script.
I was scrolling thru comments looking for an answer to this, didn't occur to me to use the
but would rather have it done automatically. Anyone else?
Just checked out ua-cam.com/video/4hyTDAWmqrw/v-deo.html and right around 5 min is the resolution. Thanks Mackievellian
This is so good, thank you! Question: how do you make a noise play when a letter appears (similar to how it happens in Paper Mario and Undertale)? Thank you!
(create event)
lastcount = 0
(step event)
if keyboard_check_pressed(vk_space)
{
charCount = 0
lastcount = 0
}
if lastcount + 1 == charCount
{
lastcount += 1
audio_play_sound(//voice that you want to play , 1 , 0)
}
@@inhphamlehoang9029 Where would this go in the step event? (I assume this is the text box's step event yes?)
My problem is that the second time you interact with the NPC and the text box plays, it's different...? I changed the stringHeight because i wanted more space between the lines of text, but only applies it to the second time i let the textbox play. The first time I interact, the stringHeight is not correct and the x and yBuffers are off by a few pixels. I'm really unsure how to fix this.
Thank you for these videos.!
thank u sm
I found out you can multiply the x, y coordinates of the textbox by 0 to make it go to the top left and then just add to the x, y to move it around.
Thank you so much
I ran into an issue at the end, where the text was too high up the first time i interacted with the object, but the second time it was in the right place. Is there a way to fix this?
can i subscribe twice this was wonderful thank you so very very much.
Haha thank you, that's very kind!
Your Welcome , The Array trick really pays dividands in my mind especially when i'm starting to think how it could be used to effect states.
Thanks a lot, you helped me so much!
thank you very much, this is excellent.
Nice job!, but just some advice in case you didnt know, you should arrange your arrays starting with the highest number, so that it allocates the whole amount instead of reallocating data for each entry, (Saves space)
cool tutorial overall, thank you very much =D
Anyone know how to fix the problem of a word being made, then skipping to the next line as it's being spelled out? Like say you have a 10 letter word as the last word in a line, it will be on that line as the first 5 letters are ticked onto the screen, but when it gets too long for the right side of the box, the whole word jumps to the next line to finish being spelled out. It's a small thing but it annoys me...
Thank you!
thank you!! that was so helpful!
Thanks a bunch! I really wanted to add some text boxes to give my digital games project a bit of a boost in quality and you definitely delivered! Now I wanna make all the trees talk just to show off haha! Now... How to make the textbox appear in the bottom left or middle...
Hi! How are you?
Do yo know how to set the box appear in the bottom part? If you don't, don't worry. Thanks!!!
You can try setting the x and y values to be the x and y values of the camera, and then just add to that until it's where you want it
my text box is appearing behind the sprites. is it a layering issue or is it a code issue? and if i wanted to move the textbox to the top of the screen whilst keeping the player still, how would i go about that?
I wish I could give you a million like for every video have made :)
when I press the key the text only shows up for like a split second, anyone knows whats going on?
i have the same problem sadly - ik this comment is old but did you fix it?
@@lumon_ yes I ended up writing my own textbox code.
Great - thanks for replying :)
Pretty good tutorials. Too advanced for me thought (yet). Subscribed
Cheers! Haha yeah -- if you're just starting out, I wouldn't jump into textboxes just yet. I'd probably recommend starting with things like movement and collisions.
FriendlyCosmonaut My thoughts are that the use of instances is what most people find difficult. Tbh i know movement collision basic AI and have done some mini projects , but still found this a little bit advanced . Ill try watching 2 or 3 times ...
Awesome!
Great thanks. Only problem I am having is getting something to happen after the dialogue, like the npc walking away. Anyone know how I could do it?
Your system is neat. Even tho i would like to see how can you trigger events when certain page is on the screen. I already found some solutions but i doubt i did it right. My main problem is that i can't put events on the 0 page because 0 page will trigger events even after i leave dialogue screen. Any suggestions?
Hey! Sorry for the late response. My idea for this got a bit wordy, so I've packed it all into a pastebin:
pastebin.com/hP32a90x
Very helpful.
thank you! keep it up
you're wonderful
thank you for the incredible tutorial!
just out of curiosity, i was fiddling around with the position of the box. i had it follow an object that would always stay in the bottom area of the camera view for the game. this way, i had the box always travel to this object, which would make the text box appear at the bottom of the screen. but now, even if i return it to the original position, the text seems to jump to a lower y coordinate after re-engaging the text box.
any ideas on how to help? if not thank you for the incredible tutorial either way.
edit: it had to do with the string length variable, it only works if you dont move the box. at least for me.
I love your tutorial, but there's an oversight.
If you move away from the NPC while talking to them, the NPC deletes itself, and the game crashes after you are done with the dialog... this is due to having the "instance_destroy(); " right after checking with if the space bar is pressed on obj_parent_talker
removing this line of code fixes the issue, and leaves the textbox in place until you are finished reading!
Thank you so much this guide!
Thank you! Ah, that line is supposed to delete the TEXTBOX when you move away from the NPC, not the NPC. So it should say "with(myTextbox) instance_destroy();" instead of just "instance_destroy();".
Yeah, I was going to say, It sounds like you are deleting the object NPC rather than the textBox itself.
Great tutorial thanks a lot! :)
Any tips on creating some kind of "conversation" system based on this? For example, changing the name of the character (alternating Susan and Bob for example) and changing the position of the text box (depending on the character who is speaking).
Hope my question makes sense! Thank you :)
I'll likely be making a video on this in the future (for the farming RPG series)! But for now, I'll tell you the logic of what you could do. We could make our "text" a bit more complex: instead of just a 1D array, we could use a 2D array, so we could specify who is saying it. So for example:
//First line
text[0,0] = "Hey there.";
text[0,1] = obj_bob;
//Second line
text[1,0] = "Oh hello, Bob!";
text[1,1] = obj_susan;
And so on. And then when we spawn the textbox, you could have it access the array variable for which "object" should be saying it, and move the textbox relative to that object.
Hey FriendlyCosmonaut! i'm not sure if you still comment here but firstly, thank you so much for these tutorials they are absolutely amazing! :D
I just wanted to find out if you could help me with this (i'm new at this so might be jumping in to deep water here). I'm trying to make it so when you talk to a character it changes from a "normal" state (character moves around) to a "talking" state (character can only press space to talk/disables directional movement control). It works perfectly if you talk to the first child of the obj_parent_talker but it doesn't seem to work on the 2nd child. I also noticed that when you talk the to 1st child the myTextbox calls back (i think the instance number which is 100078) however when you talk to the 2nd child it comes back as -4. Do problems arise when you have more than 1 child? I hope that makes sense.. thanks again!!
Hi! This is a wonderful video and I definitely love it! I was curious if you had or knew another video which could be followed to implement an achievement system where the text a character was saying would change after the achievement was gained/item was given. Thanks!
Ah, unfortunately not. I'll be looking to do something similar in upcoming tutorials in the Farming RPG series on dialogue. For now, if it's something that will occur immediately after an NPC has been spoken to, you could just have a variable change when the textbox gets destroyed?
I was thinking about doing an "if" "else" statement on all of it, such as "if the character doesn't have the item then use array 1-4, else use 5"
Great tutorial. Any idea how you would delete the text box after the last page rather than scroll through the text again?
I can't seem to work out a way to destroy an NPC whenever the textbox destroys itself.
More specifically, destroying the npc that said the text.
Hey! your video is the best! It helps me alot with the RPG game that i am now making, but still i got one question i want to give the textbox a specifike place like at the bottom of my gamescreen. is there a way to do it? sorry im a huge amateur :/
Thank you, I'm glad it helped. No problem - I would suggest putting everything into the "Draw GUI" event (literally copy everything from the draw event and put it in the draw GUI), and then everywhere we put "x,y", replace those with specific co-ordinates that you want to draw the textbox. The Draw GUI event will draw the textbox at those specific co-ordinates on the screen regardless of views (it is not affected by it). Here is a bit of info from the docs on the Draw GUI:
"The Draw Gui sub-event type falls under the Draw Event category and is specifically designed for drawing GUI (Graphical User Interface) elements that are not affected by the view scale or rotation. This means that you can have an instance draw all the elements for your HUD without having to base all the positioning of the elements on the the instance position within the room or the position of the current view.
When drawing in these event it is important that you understand that the draw coordinates do not change even when views are active and (0,0) is always the top left hand corner of either the application surface or the display (see the note at the bottom of this section), and the default width and height are 1:1 with the application surface. "
Note: If you have scaled your game up, the text in the draw GUI will not be scaled -- so you'll probably have to make the font larger.
Another good thing to note is if you're using views, you'll want to put this line at the start of your Draw GUI event:
display_set_gui_size(camera_get_view_width(view_camera[0]),camera_get_view_height(view_camera[0]));
This is because the GUI uses it's own resolution, separate from the view's resolution.
The first tutorial was great but I can't get past the first part of this one. I'm not getting any errors and as far as I can tell I have the same code as you, but my vk check doesn't seem to work with any button I assign and it stays on the first page of text. Please leave the code written out to check ours against. I liked the first video so much.
Thank you so much TuTTT
how do i make it if a variable is true then it will activate a different line of text instead of just reading all the text in the create event?
i'm no expert but here's my guess: in the step event of your npc, you should have a line called myTextbox.text = mytext; or something like that below the instance_create_layer line. I think you can put stuff like "if variable = 1 {myTextbox.text = mytext} else {myTextbox.text=adifferentarrayofdialogue}"
or! you could make mytext an array full of arrays! for example:
myTextbox.text=mytext -> if variable {myTextbox.text=mytext[1];} else {myTextbox.text=mytext[0];
and in create you can assign your dialogue like:
mytext[0]=["1", "2", "3"];
mytext[1]=["4", "5', "etc"];
What if I don't want them to say the same thing every single time? Should I do it with object states?
I have a question that has been holding me back for a long time. Is there a way to make the text wrap the word BEFORE it starts typing the word?
For Instance
"Hello my name is reallylongnamedman."
When it types it would say, get halfway through his name, then jarringly jump down to the next line.
Is there a way to make it KNOW it won't fit and just start it on the new line?
Or do I have to manually add the line breaks at that point?
If you could answer this it would help out a lot!
Yes, there is a way! Well, there's many. Since I'm going to do another video on this in the future, for now I'm just going to point you towards a great tutorial by heartbeast on this topic. The system will be a little different to ours, but the solution will be perfectly adaptable. Just note that in GMS2, the "#" symbol to go to a new line is now "
".
The relevant part starts here: ua-cam.com/video/8kL4kfWiLsg/v-deo.htmlm59s
I have a couple of issues
-- I used the -bbox_bottom as a depth system and all of my objects are above the text box, I tried a lot of tutorial and different method and couldn't get any to work so Idk how to change it
-- how do I change the thickness and color of the rectangle?
-- how do I set the box place relative to the viewport?
edit: had another really dumb issue that I solved lmao
Your dialogue is awesome and easy to understand, I quite learned a lot of things from it and I thank you so much for it.
I have one question if you don't mind and that's : "How can I create "obj_textbox" using the views ?", because in the tutorial it was created in a room with no views. I did tried to use view_xview and view_ywiew instead of x and y in the drawing event (for text and sprites), but it didn't show up in screen.
You mean so that the textbox will appear relative to the views? The "view_xview and view_yview" are for GMS1. The corresponding functions in GMS2 are camera_get_view_x() and camera_get_view_y(). You also have to tell it what camera to get the x and y position of, so if you're using view_camera[0], you'd put: camera_get_view_x(view_camera[0]).
Note: This will get you the position of the top left corner of the view, so you'll want to add to both values to get it somewhere reasonable on the screen.
Some bug fixes i noted for anyone needing without searching much! Anyone can comment down if they know how to fix more efficiently than me (im still a noob afterall),while also ill be editing any new fix i know
(Edit now i know how to make it work with viewports :) )
1- how to make the textbox centered/in a different place than origining from the character?
i went to the draw event in obj_textbox,in the draw_sprite part,i changed the x and y values to custom numbers of where i would want it to be made, example = draw_sprite(Sprite3,0,6,511),i just changed the x and y to 6 and 511(it can be any number,thats just mine)
Do the same thing in the draw_text_ext Xs and Ys, pro tip: make it slightly different than the box's X and Y if you want Something more centered like the text's X being a little less than the box's X
THEN copy allll the code in the Draw event of the obj_textbox and move it to the Draw Gui event,so it can work with viewports! Its just a matter of changing the Xs and Ys to custom ones
2- how to make the player stop/pause while theres a textbox?
make a object called obj_pause
it doesnt need a sprite or any code at all,it just need to exist
go to your player events,step event
put this code(that im putting bellow)above all the lines of movement,like before any coding that changes the player x and y
if instance_exists (obj_pause){
(whatever variable for the movement keys you made,right or right_key whatever)
right_key = 0
left_key = 0
}
note: right_key,left_key whatever are my variables to the movement of the character,if your variables have a diff name like example "right = keyboard_check_pressed(vk_right)", put the variable "right" inside the "if instance_exists(obj_pause)" code,just so you dont get lost if yours are different
then,go to obj_textbox, parent and put obj_pause as its parent
what happens? whenever a instance of obj_textbox is created,a instance of obj_pause is created,meaning you cant move while the instance of textbox exists! and since the textbox is destroyed after the pages are done,the obj_pause is also destroyed!
3- text lines appearing squished togheter for the first time the textbox is made,and getting fixed the second time its made
honestly i dont know how to fix it yet but a good idea is to just make the first textbox's text being short and not being long enough to have 2 lines of text, so once all the other ones are made they are already fixed
Some ideas like the obj_pause i got from peyton burnham so thanks to him for that lol
Hey @friendlycosmonaut
Great work.
A quick question! What sort of logic would I use to make my text boxes spawn in a standard, bottom centre location of my current view, rather then spawning from the NPC we are currently interacting with?
You can use "Draw GUI" rather than the "Draw" function and set the y value to (your view width - the height of the text box) and x to 0 Hope this helps!
@@aaronsomelastname4316 thank you
Thanks so much for the great tutorial! I've encountered a bit of a strange problem where the dialogue system works perfectly the first time the player talks to an NPC, but every subsequent time dialogue is prompted the text is written at a lower y position on the screen and stays in this new position consistently. I've been looking over the code for hours now and can't seem to find the issue, so any help would be greatly appreciated!
Exact same thing is happening to me. I don't know how to fix it :( Have you found anything?
@@ASSORTEDJELLIES I couldn't figure out a solution so I ended up scrapping my code and following her new textbox tutorial in the farming rpg series where I got it to work. Hope you're able to figure it out!
@@heater454 I still have the issue, could anyone help us on that?
guys, i have problem. trying to index a variable which is not an array
at gml_Object_obj_textbox_Draw_0 (line 10) - draw_text_ext(x,y, text[page], stringHeight, boxVigth ); wtf?
Thanks for this awesome tutorial!! Would it be possible to add a tutorial for scrolling text when a string is too large for a particular page?
Haha possibly one day, but it may be a while. But I'd wager someone has done a tutorial on this topic before so you might have more luck searching around.
I actually figured it out on my own :) Instead of using a sprite I just used draw_rectangle and calculated the size it should be based on the current text so that it grows with the text (up to a max width I've set).
Ahh yes, dynamic boxes are a great solution to this!
I have question there is posibilyty to do something like this: where "draw_set_alpha(alfa);" will be change alpha on only one element?
ok I find out: "draw_text_color()", that solve my problem :D
Hmm interesting how the ext seems to do the same work as pre-formatting the text. It's hard to tell in the example, though, does this function automatically wrap text while printing out or do the first few letters appear at the top before dropping to the bottom? I'm guessing the latter since you aren't running a format function on the text but only wrapping it live during the draw, so I wouldn't imagine gamemaker automatically knows which words to return on. And text length? I'm presuming if you used a text of sufficient length, it would probably print off the end rather than doing some kind of scroll effect. Which I would imagine are the reasons to still pre-format text for maximum flexibility. Do you plan to do a more advanced text tutorial in the future?
I also had a question regarding a more advanced feature of text boxes that I kind of got used to when I started scripting for Morrowind. In that engine, you could use a % sign to indicate a variable such as %PCName. This will be a valuable function in my current project as well, but everything I've read to date indicates that all functions to pull script or variable names out of strings are gone. Do you know how something like this might be set up in gamemaker? Will I just have to come up with a text processing script that assembles strings from a signal symbol like this one and compare their values to a list of possible variables?
Yeah, the first few letters appear at the top -- it's only wrapping the text by the letters. It's a pretty simple function, and won't do anything like scrolling. Definitely programming it and formatting it yourself would allow you to be more flexible. I definitely would like to do an advanced tutorial in the future -- where we basically do everything ourselves, so we eg. wrap the text by words, add sound effects, and throw in effects (colours, moving letters, etc). To be honest though, I can't say when that would happen, as there's a lot I want to do in this series first -- I'd say it's months off.
There's a function called string_replace(str, substr, newstr), which replaces a part of a string with another. But if you wanted other kinds of functionality, I believe you're correct - you may have to write the scripts yourself. For example you could increment a position variable, and check each character of a string using string_char_at to see if it returns the first letter of the word you're looking for, and if it does, check the NEXT character and see if it is equal to the second letter of the word you want, etc. If it finds the word, your script could then return true, and go on and do other things -- delete the word, insert a new one, etc.
Wow, thanks. That is so much easier than I feared it would be. And the best part is, I can run it once while formatting my text and adjust the width afterward, so I don't have to worry about someone using a really long name like MisterMcSnarkyPants. I'm not too worried about pulling non-text variables out of a string for now, but I'll just have to dig a little deeper if that becomes a concern. Now to figure out the scrolling action.
Can't say that I blame you for wanting to finish the series first--but I can't wait to see the advanced version!
Very nice video! But i am a bit confused: You are defining the myText array in obj_susan. How can the obj_textbox know this array? Is it because of the line "myTextbox.text = myText"? Does this line "transfer" the array to obj_textbox?
Yes, this is exactly right. The variable "myText[0]" is a specific entry of the array, but just "myText" represents the entire array. So we have indeed transferred the whole array with "myTextbox.text = myText".
Wonderful video! The code works beautifully, except for one tiny snag; if you press the key to skip text fast enough (space in your case) the text will start looping over itself infinitely, locking the player in the textbox event. Do you have any ideas for how to stop this?
Is there a way to change a certain word's color? Like a keyword within the dialogue that needs be like a different color besides white. Anyways, insanely great tutorial on dialogue, we're using this dialogue system in our game :D
do draw_set_color(color here)
the color is picked from using c_something e.g c_red, c_blue