GameMaker Studio 2: JRPG Cutscenes using Sequences Part 2/2.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so last time we had the ability to just play a sequence when the player collided with an object and we are now going to make it or adapt it so that we don't have to hard code which sequence sequence gets played we can just have an array uh filled with different sequences to be played in different rooms uh based on a particular global value which i'll show you in a minute and that will mean that hopefully no matter how many cutscenes you want to have you know there's no extra work basically apart from making the sequences themselves so i have added a couple of things so we have a brand new object called obj cutscene uh this guy is gonna be doing most of the work for cutscenes uh make sure you have it set to persistent and we also have a brand new room called rmstart uh i have the same uh well i have views enabled invisible same width and height for the camera as well as the width and height of the viewport and also make sure that this first this new room is going to be the first room uh to do that then you click on the icon here and you drag whichever room you want to be first to the top and then you should see a little house icon next to it like this and then add your new persistent persistent object into our new room and also an instance of the player uh the reason the player is in the room is we're gonna have a line of code in the player whereby we just press a button and we're gonna be warping to the throne room and back and that's how we're going to test to make sure uh sequences are being played in the correct order and we can also go to the room and no sequence will play if there is none and in our new room make sure you have the same layers just in case we get a crash so that's what i do anyway okay so we will go on to updating our code next okay so uh the first thing we're going to do is in the activate cutscene seq cutscene object in the destroy event we're going to comment out this code to do that if you just hold ctrl and k or if you do control a first to select all and then ctrl k that's a fast way to comment out everything um the reason i said to comment out not to delete it is because we're going to be reusing these this code in our new object with a very slight change to it um then in our brand new object in the create event we have a couple of enumerators uh this first enumerator is uh it controls the uh cutscene object as well as the player so uh when the main state is ready the player can move around uh when the state is cut scene uh we don't take player input um apart from uh dialogue boxes and this is the state system for the cutscene objects i'll explain the states as we get to them initially the cutscene object is going to be idle so nothing should happen in that states apart from one event which we'll get to in a minute and the main state is going to start as ready so that so the player can move around we're also going to have a global variable called global.storyval this number is just basically gonna track where the player is up to in the story and uh you can just increase this however and whenever you like uh the way that i'm doing it is um after every sequence is played this gets increased by one um in a proper game you know you'd be increasing it in other ways as well but it's pretty pretty simple way to track progress in a story i'm gonna have three story points uh two sequences in total and a third story point where you know um he's seen those two cut scenes and he can just move around the uh the throne room as much as he likes and we're going to need a 2d array that keeps track of uh what sequences we want to play based on the room and based on the value of global.story so um the yy this entry here is going to be the room uh which starts at zero and we have two rooms so it should really be less than but you know it's not really a big deal as long as you don't have like a huge number for it and uh the same for story points so initially every entry in the range array is going to be set to minus one and then we're just going to overwrite it underneath so you can see uh in cut scenes zero and throne room we want uh this cutscene the very first cutscene that we made to play it's not a very good cut scene but you know it's just something to show you for now um and that's it so you can see i have this commented out where when i make a second cut scene then i'm going to update the array with that as well so that is the create event okay so it's actually going to make more sense to you now if we do the player step event okay so previously this was our code uh we're going to update it so we have this code here so now we have a state system we're going to wrap our code in a check to see if the main state is ready this code is the same as before just checking for a collision um this code has been updated so previously if there uh was well this line is new so basically we're checking to make sure that there is uh first of all a cutscene object that was the same as before but also uh there actually is a sequence to play so remember every entry in cutscenes um is gonna be minus one um which means no sequence to play and then we overwrite it if there should be one so if there is a sequence a sequence to play and we're going to change our main state to cutscene and we're going to change our cutscene object state to init which is going to start the cutscene to play um and then this was our old code where we destroyed the other cutscene object but we don't need that anymore because we're actually not going to have any code in that other object it's just going to be blank basically just used for collisions um this is the same as before you know moving left or right very basic movement code um and then this code is new so uh this is when we press f5 we're just going to check which room we're in if we're in room start then we're just going to go to the throne room if we are in the throne room then we are going to go to room start so that's how we're going to be able to quickly test our sequences and our story uh tracking ability okay so now we are actually gonna do the room start event uh before the step because again uh this is gonna be happening this event happens before the step so uh to get this event you just add events or right click whatever you want to do then go down to other and then there's a room start event so uh because our cutscene object is persistent every time we enter a new room this event is going to run and what we're going to be doing is checking whether there is actually a sequence that we want to play um whenever the player hits the cutscene object in that room and uh just kind of get things ready really and this is actually going to be the code from the activate cutscene so if you do control a control a and then control k no i'm sorry control and then control v to copy it all and then if we go into our new room start event and paste it i'll explain to you uh the differences in the code so this line here is just showing me uh what is actually stored inside our 2d cutscenes array just for debugging you don't have to have that but you know um it will help you out if you need to need to debug something um here this this line is new so we're just checking that there actually is a sequence to play in our array so any instance sorry any entry that is minus one means there's no sequence basically um and this is a huge part of what makes this system work is we're actually grabbing the sequence from our array and this line before it had this uh it had the name of a sequence so basically hard coded it so we this line was always going to run the same sequence but now we're doing this sequence here whatever is stored in this array it's going to get run basically so wherever you see the sequence just make sure that um uh sorry just uh yeah on uh in my code here wherever you see this sequence make sure you have it because that's mainly that the main difference in the code is this as well as this line here so and then this line here but it's it's basically basically the same code and uh if you didn't see part one i'll just briefly explain to you what we're doing so um we grab the sequence you want to play that there must be sequence because it doesn't equal minus one um we're creating an instance of the sequence and storing it in global.current sequence um we have objects in our sequence that we want to play um and we those objects are stored inside an array which we're going to get with these three lines so right now um we have an ob we have a an array of objects that are stored in that sequence and we're going to check them one by one to see if any existing objects like that exist in the room already one thing to know is right now the sequence hasn't actually made any objects there's an array of objects that it wants to make but it hasn't made them yet so um if an instance exists of any of those objects in that array that means there must already be an object object in the room and that's how we know uh which object to override with what so room object instance is going to be the first instance of the sequence objects that we find so for example in the sequence we have obj player and in the room we have obj player so there's two instances and the one in the room should be the first one because the sequence one hasn't been made yet so um and we just overwrite the sequence instance with sorry we overwrite the sequence instant objects with our room object so that's all this loops going to be for and that's what allows us to uh move the player in the sequence and then once the sequence is finished the player is in in the same position and we can move him move him around and then we just pause the sequence because we might not want to play it yet because uh the room's literally just started uh the player might have to walk into uh you know he might have to walk a bit further before the sequence starts so that's why we're pausing it okay so uh the final event we're going to do right now is the step so if you remember when the player is colliding with the activation object it checks to see whether there's a sequence to play and if there is uh it sets the uh the player sets the cutscene object state to init which is gonna start the sequence to play and then the sequence object sets its state to play which is this state here and literally all that's happening here is uh the sequence is checking to see if the sequence has finished playing if it has then it gets rid of the instance of the sequence that it has created it resets global.current sequence to minus one and resets its state to idle as well as the main state to ready which allows the player to move again if we run the game now we should be able to make sure this runs properly so we press f5 well right now i can move left and right as you can see i'm going to press f5 the sequence is playing and that's it i can move again so it's it's nothing fantastic but uh this is a huge step forward because now uh we can have lots of different sequences in the array and uh depending on the story point uh different ones are gonna get played uh of course this the global.story val isn't being updated yet but i think this is probably a good point to uh improve our sequence so we're going to be doing that next okay so as usual there is a bit of code to do first uh we have a little bit more setting up basically we want to be able to change our actors sprites during a sequence and the way that i've done it is i have an array called actor objects and then every entry is going to be a different object [Music] depending on how you have created your game you may need to do this a slightly different way because this array kind of depends upon every npc being a different object which i normally don't do in my own games but this was like the simplest you know most most straightforward way i could think of to get the point across so hopefully um you don't find it too hard to update if you do let me know i'm sure i can help you out with that anyway uh so we have an array we have uh the player and npc stored inside it the reason what this is for is so we're going to make use of broadcast messages to send a string the string is going to tell us which entry in the array to access which is going to give us one of these two and then there's going to be a second number which is going to tell us the facing to use um and you might not understand what i'm talking about or you won't understand that so if we go into the create events of the player uh we have a newer enumerator called facing or e underscore facing uh we have up down upright down the left and then uh each actor is gonna have its own array like this called move sprites which just stores uh what sprite should be used by the actor for what facing so this is the creative event for the player and for the mpc very similar uh just this array you can copy and paste the array and update the names of the sprites like that okay so um now we have done the setup uh to show you how this works well actually there's one more thing to do all right um we're gonna go into our sequence and you can see at the very start the player is facing the wrong way so uh we want to make sure that doesn't happen so we're gonna click on we're going to make sure the uh the the line is at the very start of the sequence we're going to click on broadcast message i'm going to type uh dollar sign and then 0 because you want to change the players facing and then zero is up so uh that's gonna tell the game what facing to do you press ok you can see we have a broadcast message and all these are for is for sending strings to whatever object is listening for it which we're gonna do next okay okay so now we're gonna make a new event uh broadcast message uh we're going to add event and then other and then at the bottom there's broadcast message that's what we want and so you can see the top here um we have if event data question mark event type is equal to sequence event then do all this stuff this line is taken from the manual for broadcast messages and what it is is uh event date event data is a ds map and it just stores you know data inside that and then um this event is listening for event data and it's listing for the event type of sequence event so um when you put a broadcast into a sequence it becomes a sequence event that's my understanding of it anyway so we're actually interested in the message part of this dsmap so we're going to use a new variable called broadcast string and it's going to store whatever is in the message part of event data which is our string which is uh dollar zero underscore zero right now okay that's what string is and just for testing debugging i'm going to show that value that string sorry inside of the output here okay um we're interested in the first part of our string we want to know what symbol is it because we have a switch switch statement here which is going to go through the different symbols and do different things depending on what symbol it is just in case you need lots of different symbols uh there are other ways to do this for example you can just use one symbol and then the numbers that come after that symbol uh determines what's going to happen uh but i'm trying to keep this as simple and easy to understand as possible so i'm using a different symbol for different things so what we're going to do is uh check what symbol is so that's what sim symbol is gonna equal a dollar sign right now because we're sending it a dollar sign uh under dollar sign zero underscore zero and then um i've got this uh comment here just to explain something but let me uh do this these three lines first so what we want to know right now okay is which entry in our actors actor objects array we want to know which entry uh the string is referring to and the first number that comes after the symbol is going to be that number but um it could be a single digit it could be double digits it could be you know triple digits so we can't just say okay whatever the second character is that's the actor because that might not always be the case so we are going to use a loop that's going to check each of these characters in turn and then when we get to this underscore then we're gonna say okay uh we must be done with numbers now so whatever has come before it is gonna be the actor number to do that we're going to have a new variable called index i'm going to start it at 2 because in strings this is 1 this is 2 and i'm going to have a new another variable called car which is going to store the value of whatever is in the string at that position so when index is one car would equal a dollar sign but when index is two which is what we have set here then car is going to equal number three so winning index is two car is three and then actor id is eventually going to store all of these numbers so 300 but right now we're initializing it at nothing and then we have this loop here which says while string digits car is not equal to an empty string so uh why are we doing that we want to know basically at what point in this string does car no longer equal a number and to find that out there's a useful function called string digits which basically turns um it it only returns um a string with any numbers inside of it say for example you had uh a156 or a1 sorry yeah a156 this will just return one five six if you had egg it would turn nothing if you had an underscore it also returns an empty string like that so basically this loop is going to go through our string and until it finds a non-digit and then we're done so for as long as car is a number we're going to add car to actor id so when index is two car is three then actor id is gonna equal three then index gets increased like here so now index is three car equals string car at broadcast string index so cars now can equal zero which is this one oops and then car because car is a number it gets added to actor id and then index muse here equals four car is zero again which is a number so it gets added to actor id and then index gets to here which is five car equals an underscore it's not a number so it doesn't get added to actor id and then this loop is done and then whatever actually actor id equals it becomes the real of itself so it just turns itself into an actual number as opposed to just a string okay so um that's how we get 300 as the number right now obviously our string is just uh a dollar sign a zero underscore zero so the message that we sent is getting gonna end up with an actor id of zero but it's just worth understanding uh why we are using a loop and how it would return uh numbers that have more than one digit okay so um that's that and then uh if you remember right here index is equal to five and then we actually want to know the last digit as well because that's going to be our facing it's either going to be 0 1 2 or 3. so to get that we use far facing equals the real of string car broadcast string index plus one which is here it's going to return zero once we've done that we just can make the instance change its sprite so actor objects actor id which is zero dot sprite index equals actor objects actor id dot move sprites facing so whatever spacing is going to be zero one two or three move sprites stores the sprites for that object in its own array um and that's it we're just reference referencing the object directly from the array uh bear in mind that in game maker whenever you reference an object you're always going to return the first instance of that object so if you have uh 20 instances of the same object this isn't going to be a good way to do it but uh to keep things simple uh i've just done it that way so just bear that in mind and then uh we're done then with that case we just break after that's done because that's we've done what we need to and and that's it so we're done with this region right now so uh if we run the game we can see this happen so press f5 you can see the player starts facing up but in the room itself in throne room he's facing down and in the sequence as well he's also facing down so when he enters that room he's only facing up because of that broadcast message basically uh what to do next is kind of a toss-up between uh the text or um having multiple sequences you know and progressing through the microstory um i think it's going to take less time to do that so we we're going to i'm going to update this first sequence and then make a second one so uh i'm going to probably make this about 300 seconds long and then see how they all stretched cool okay so this keyframe is when he gets here and then i'm gonna have the npc i'm gonna make him move around the player so let's give him a keyframe and then like here it's going to be from that there see if this works cool and then [Music] give him another keyframe and i don't want him to move any grids on there we go let's try this out that didn't work very well let me just delete some of these click on these keyframes and delete to delete them so we're up to here right now then when he gets here i want him to have moved to there does do that okay it does and when he gets here i don't want that to block that let's test it no when he gets here i wanted to have moved down here actually that's making me further than that [Music] oh no that's wrong so i'm going to say 25 frames for every tile so uh we'll move four so one two three four one two three four oops so let's try this now there we go and we're gonna have the player well let's let's do the uh npc so from here he needs to face left which is going to be another broadcast message so broadcast message it's going to be dollar one underscore one and then here we need to tell interface right uh down again which is number two so dollar one underscore right down so if we run the game and play the sequence we'll see that in action there we go awesome and i'm gonna have the player character uh turn so [Music] when he gets here around about here i'm gonna have the player turn to facing so another broadcast message dollar sign zero uh and then it should be one i believe to face right and then as he gets to like here maybe have the player face down so dollar zero underscore and two so let's run the game see how this looks and i think i'll have the player move towards the same location and that will be the end of the sequence so uh player so we're up to here if i add a a key for the player and then one two three tiles we want him to move to here let's just play that see what it looks like oh it's too fast maybe i'm going to extend the track a bit more okay so here's the player okay and then one two three i want him to move from here to here in that time there we go okay right and if we run the game press f5 make sure they're all facing the right way awesome okay so uh i'm gonna go ahead and create a second sequence but i'm gonna do that off camera um hopefully you've kind of seen how i have made the characters move around in this first one the second one is not going to be uh any different um so we'll do the second sequence i'll show you how to increase the story value and how to play different sequences based on that value and then we'll do the text and we will be done okay so i've just made the second sequence i'm just gonna uh make sure that it looks okay um so i'm gonna go into cutscene create event and then change uh where are we there it is change the one to a two and then run the game again f5 so they meet in the middle play spins around and and that's it so we're now going to uh we're now going to like i said increase our story val at the end of each of these sequences and all we need for this really is a script so let's make a new script i can find what the hell oh that's why custom order helps me a lot better there it goes the scripts i'm just going to call it uh increase story file now we're going to do is global. storyville plus plus so increase story val by one and now i've done this i'm going to go into obj underscore cutscene in the create event i'm going to now enable this line so now we have two sequences ready to play and the only thing we need to do now is actually implement our script and if i go into each of my sequences the very end of each of them i'm going to add a moment which is this lightning bar and you can just put the name of a script inside here so i'm going to say uh i'm going to type increase and then here comes a script you can't pass it arguments if you could uh we'd probably use that for changing sprites but you can't so uh we're going to use it for this so all you have to do type that okay and then in the second one at the very end again click on the lightning type inc there we go okay and i think we can test this now see if this works so every time we go to the room we should see a new sequence and the third time there should be none and the player should be able to move left and right because they haven't given him back and forth movement yet but anyway so this is the first sequence now i'm going to press f5 and again this is the second sequence left and right and a third time no sequence and we can move around and let me show you something else say for example uh yeah so basically just by increasing the global.storyville that's how we get uh different sequences to play in different rooms at different times um we could do a test where we have a gap in between the sequences so when the global story value is zero we play a sequence and then when it's one we don't and then when it's two we play another sequence and that would work all we need is some kind of uh key press let's do it actually let's let's let's test this so um let's go into here and then we're gonna comment this out and we'll say two equals sequence two uh my story points that should still be okay okay and then we're going to need a key press to increase story val so we're going to the player step event i'm going to copy this line line 31 for pressing f5 and we'll say if we press f7 then global dot story file increases by one there we go so let's do the test run the game so we go to the first room we see the first sequence i can move go back to the room and go back here again there's no sequence if i was to now press um [Music] f7 we should play we should be able to see the second sequence is that right no we have to change the rooms okay so let's go back to the main room and then we'll press f7 now and then go back to the throne room and now we get the sequence so uh as long as we play within the rules of the code that i've done you know uh it doesn't you don't have to have the sequences play after each other you can have gaps you know um and this should scale well okay so now we have to make a new object called obj underscore text engine uh make sure you make it persistent because we're just going to place it in the main room which we'll do now so in in room start i have these two objects and then if we go into the create event we have a state system rather going to hide the text or display it and then we're going to have one variable for now uh called total text to display which is you know all the text we want to display uh first of all we're just going to display all the text at once and then uh the final part will be uh having talking text i figured that if i do that last then um you know hopefully that that will save some people time because they may not want talking text why won't you i don't know anyway so uh end step event we have um what will happen is in our sequence we're going to use broadcast message to send a message to our cutscene object that cutscene object is going to pause the sequence and then we will have some text to display which means this is going to be true and if we press space while there's text to display we're just going to play the sequence again and reset our text to nothing and then we have one more event which is the draw gui so if there is text to display we need a new font i'm calling mine fnt mana if you want to make that now get out of the way uh i have it is size 24 and i'm using a mono space font which means every character is the same width which is useful for talking text not mandatory but it's useful um if you want to use the same font that i do then just search for mana space download mana space font and you'll find it easily enough um so back to the draw gui so we've set the font uh h alignment for alignment we want to draw from the top left and the color of the text is going to be white uh this stuff here uh looks like a lot it's literally just setting up the text box so uh font size is the size of our font margin so the space that we want um between the sides of the sprites and the text that's what margin is going to be used for let me just show you one thing as well so i know this was at the start of part one or part two but we're going to be using this text box now which uses nine slice so this is what sprite that i'm talking about right now okay uh box width and box height um literally how wide do we want the text box to be and how high box x and box y at what position on the screen do we want to display the box um the origin of my text box is the bottom center so like right here so if we look at the box y display get gooey height so it's gonna be displayed from the very bottom and very middle of the screen and x scale and y scale is based on the width of the box that we want to display divided by the actual width of the sprite same for the height that's going to tell nine slice um how big oh sorry the scale to draw the box basically so that's all this stuff is it's just literally just to set up the text sprite then we're going to draw it let me zoom out a bit so this line is going to draw the sprites and then i'm going to break down this line into two this is what draws the text so i'm going to draw it the x coordinate is the margin the y coordinate is box y which is the bottom of the screen minus box height which is how high the box is plus margin so it's basically the top of the box plus whatever margin equals that's going to be the y coordinate of the text and then total text to display that's our whole message um separation so we're using draw text ext which is going to draw line by line just one whole string and it's asking for uh the width in pixels between the lines which is this font size times 1.5 which gives us a nice space and then finally uh the width of the line so how much space across the screen should one line take and that's going to be display get good width minus margin times two because you want the text to display the whole screen width but have margin on either side and that's it so one last thing to do is actually put a message into one of our sequences so um when the player gets to here it's going to be i'm going to i'm going to put the message here for now but it's going to look a bit weird because the mpc is going to move first but i can you know i'll fix it afterwards anyway so um and we are going to and we are going to use the at symbol so click to make a broadcast and then i'm going to do at and then hero and then oops double click to open it and then there we go that'll do and the last thing to do is keep saying that uh the last thing to do is to update our cutscene object in the broadcast message event so uh in our switch statement we have a new case which is the at symbol which is what i just used in the sequence uh it's not very big uh let me zoom out there we go so if you if you remember the first character of the string is going to be the symbol which will bring us to here um we just want to tell the text engine to display the string so uh we want to miss out the symbol so we're going to use string copy we're going to copy the whole string but only from the second character which will skip out the symbol and and total text to display is going to be the whole string minus the first character basically and then um we also want to pause the sequence so we can allow the player time to read the message however long they want to take and then press space to recontinue so that's what this is about if we run the game we can see this now see this in action now so press f5 and here we have a message you can see the sequence is paused it's going to stay like this until i press space which i'm going to press now and that's literally how to get interactive text into a sequence okay so now we're going to get on with talking text uh there's quite a lot to it i don't know if my code is efficient but you know it does the job anyway so uh we're going to need to add a couple of things in the broadcast message event of obj cutscene uh we're gonna have two new variables for the text engine we're gonna have uh i'm sorry one one new variable at least display text so we're going to have uh total text to display is going to be the whole string that we want to display and then display text is going to have a character added to it every uh draw event so which is usually every step but anyway um and that's how we are going to gradually show the text and we're also going to use the state system that we made that i haven't used yet so we're going to set the states of the text engine to display and then inside the create event of obj text engine we're also initializing our new variable display text and in the end step uh we're no longer setting total text to display to nothing we're just going to use our state system to hide the actual i'll change the state which hides the you know uh the text box and the text and then in the draw gui okay so first of all we're replacing uh if total text display is empty with our state checking we are displaying it uh these variables should all be the same as before uh then we have a region of new variables so we want to know uh how how wide do we want to allow our text lines to be then we're going to calculate calculate the start position of text x and text y which is going to be based on the origin point of the sprite uh but we want to start basically in the top left of the text box and then these two lines here are what is adding uh characters to display text pretty simple for now and then this region here is like 90 lines long so we'll get we we're gonna get on with that now okay so draw character by character so we have all these new variables um basically we're setting up setting these up to tell our text engine uh the rules so uh car index is going to track the progress along the string in the same way we have index in the broadcast event for our cutscene object uh we're going to use this you know this variable in the same way max cars per line so basically how many characters do i want to have per line um if you don't have a mono space font this isn't gonna work as well for you but because i know every character i'm gonna draw is the same width i can just say okay i want to have 30 characters per line but um i don't actually know how many characters are going to fit per line so i'm just going to use this formula so max text width take away font size times 2 divided by font size will give me how many characters i can draw per line max lines so um how many lines of text can i fit in my text box it's the formula for this uh characters per line so i'm going to track how many characters are on the current line that i am drawing uh because uh the main thing about this kind of text engine is you want to keep track of words because um you don't want to draw half words and find out you're at the end of the line and then draw the next half of the word on the next line so you want to check basically uh to make sure each word is going to fit on the line and if it doesn't then you uh increase your line number and then draw the word basically that's all we're trying to do line number which line are we drawing on temp index so we need a way to be able to track to see whether we've already checked um to see if a word will fit on a line because the way that i'm doing it is i'm just checking to see if a car which is going to hold the each character from the string i'm going to check to see if this is not a space if it's not a space i'm going to assume it's part of a word um but i don't want to check uh to see if the word will fit on it for his mentally for as many letters that are i just want to do that check once so temp index is going to get set to car index whenever i have checked a word so that should stop it from happening uh too often line dialogue is just going to store um the strings that are on each line we're not actually going to use them to draw although you could it's simply because um i wanted an easy way to just delete the top line whenever we get to the max lines and there's more text to come so that's the reason i have that uh there's certainly other ways to do it you just need to know basically how many uh how many characters are on that line to delete but i just decided to copy the whole string to it and just just delete that you'll see what i mean as we go along i know a lot of what i'm going to say isn't making sense but as we go along hopefully we'll do so um here while car index is less than or equal to the string length of display text so um basically um if we haven't shown all of the characters inside the display text and because it's a while loop this happens every step and then every step a new character gets added to display text and then all this is gonna happen again um text engines like this can be quite a resource and or draw intensive because you're doing so much every step i haven't found a better way to do that really um okay so get the next character by now you should understand what this does here as the comment says if the character isn't a space and we haven't checked if the current word will fit how do we know that we haven't checked well if temp index is less than car index we haven't checked so if this is true and this is true then we need to check if the word's going to fit on a line which is this region so word length is just going to track how many characters are in the current word we're going to update temp temp index we're going to use a different variable to to get the different characters from total text we don't want to use car we want to save that you know for actual drawing and stuff like that so as long as temp car is not a space just increase the index uh increase the size of the word and get the new character if at some point we've already reached the end of our total text string then we're just going to break out of this loop otherwise we'll get a crash so that's this region so after this region happens so um after this region if we have we want to do a check basically to say okay so uh if we add the size of the new words to how many characters we have on the line at the moment and if it's greater than the maximum characters we want then we have to make a new line so we're going to increase line number we're going to reset cars per line because we're starting from the left again and then um we also have to do another check because we might have had our maximum lines and so we don't want to draw below you know that uh that last line we want to delete the top line so all the other lines move up by one so that's what this region is going to do if line number is greater than max lines we have to delete the top line so we update our total text to display and display text by deleting whatever string is stored inside the first entry of line dialog remember we're only using the line dialogue this array to store what characters are in which line that's the only reason we use it just to make this bit easy and then after we've updated our two variables to hold our strings we're going to delete this first entry from line dialogue so basically you know we had we had four lines and the top line could say hi well that's going to get deleted now and whatever was on the line below moves up and you know it just all the entries move up one basically and uh because we've deleted an entry from the array we then want to reduce line number by one and you might say well you've added it here and you've taken away so why even increase it because we have to add to it to be able to check to see if we've gone past the max lines that's why and then this line here is what actually draws each character in the loop to uh the screen and like i said it happens uh this happens once per character every step so that's why it's pretty intensive um it does allow you to to do cool things though like change the font or color uh mid mid sentence stuff like that and this line is adding whatever car equals to the current entry in our line dialog array just so we can make deleting easier then we have this region here so did we get to the end of line it's just like another check um we're increasing car index and cars per line um if we have then found out okay well we have literally just got to the end of a line then we're going to increase line number again reset cards per line uh this code is just exactly the same that we had before um maybe we should make it make that into a script uh i just thought it would be easier for you to see it like this that's the main reason so that's that region and that's it so um it seems like a lot of work but uh you have to do that really if you want something like this so press f5 and then we can now see our talking text like that and then uh it's waiting for us to press space but what i'm gonna have as well uh the last thing we're gonna do is we're gonna have like a nice uh like arrow pointing down um to kind of uh give the player the idea okay you know we're waiting for your input so that's what we'll do next okay so here we go the final bit we're gonna do today uh in well we're gonna add a new sprite first and uh i stole this from final fantasy um i've just called it sbr underscore text underscore arrow this is the sprite and then in the create event of our text engine we're gonna have two new variables we're gonna have pause which is a boolean it's gonna be set to false when it's true we're gonna see the arrow move up and down we're also gonna have pause timer uh this is how we are going to animate our sprites some people like to use objects which makes animation easier i like to use less objects and just use stuff like this to animate things like that the way that i have this pause thing set up as well means that you can actually pause text uh halfway through uh we're we're not going to be doing that in this session because it's already kind of gotten pretty uh you know twice three times as big as as i thought it would be so anyway two new variables in the end step uh we've replaced this line with this line so if we're paused we're gonna uh increase pause timer by this value and that's we're going to use this value to animate the sprite like i said you'll see what i mean in a minute um we just yeah let me explain it in the drug area and then uh if we press space while we're paused then set pause to false and then this is the same as before and then the last update is going to be in the draw gui uh let's go up here there isn't too much so we had these two lines to say you know to if display text wasn't as big as total text display then just add a character um but we're gonna wrap that uh to say um if pause is false if uh display text is equal to total text display uh then we're just gonna automatically pause the text and that's what's gonna start the arrow moving up and down uh because at the very bottom this is not new oh uh i don't think i mentioned this last time but this uh these two lines were how we were drawing text before we can just delete them now we don't need them and at the very bottom yeah at the very bottom okay so here uh here's our very last curly bracket this curly bracket is the end of the while loop and it matches up with line 48 this one here uh okay and then um this region is here that this region is new we're just gonna draw the moving arrow there so if we're paused scale is six because it's a tiny sprite um pausex is gonna be to the right of the text box pause y is gonna be near the bottom but we're also adding the mod of pause timer divided by 10. the bigger the number uh the slower it goes um but also in the end step uh the bigger the number uh the faster it goes as well so uh i like these values but you know if you play around with them you'll get different results um and then we're just gonna draw our text arrow so let me show you what it looks like in the actual game f5 like that so now it's clear to the player no they have to press space like i said if you uh want to have pauses in the middle of your dialogue then you can just use a symbol for that um i don't know if it's worth me doing like another tutorial i don't think i should do it you know in this tutorial because it's already like 50 minutes i think so it's quite a long time anyway uh thank you so much for watching uh thank you to my patrons for voting for this video uh it was uh something new for me to learn and uh there's a special competition for this uh for this episode whoever can tell me how many times i changed my t-shirt in this video they will get a special prize that's it thanks for watching i'll catch you next time bye for now
Info
Channel: GameMaker Rob
Views: 452
Rating: undefined out of 5
Keywords: gamemaker, game maker, gamemaker 2, game maker 2, gamemaker rob, gloomytoadstudio, samspade, spalding, jrpg, cutscene, sequence, sequences, how do I made a sequence, how do I make a cutscene using sequences, rpg, make a cutscene, make a sequence, gamemaker studio 2 cutscene
Id: 0Ci64_xBFGs
Channel Id: undefined
Length: 65min 5sec (3905 seconds)
Published: Fri Aug 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.