5 Useful Scripts for GameMaker Studio 2 (and 1!)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this week's video topic was selected by my patreon supporters in a poll that I ran last week if you'd like to also be able to vote on what topics I cover you can do so by supporting me on patreon $5.00 Borders also get access to my videos whenever they're ready instead of just on Fridays and everybody who supports me gets listed in the credits of every video just want to mention that real quick ok let's go scripts in a game maker project can do lots of wondrous different things mostly what they used for is condensing a chunk of commonly used code down into a single command that you can then write which saves on time fingers and mental energy now what a lot of even intermediate developers don't realize is that some of these chunks of code are so common that they're going to occur across many different projects how many times have you wanted to move a number towards another number without overshooting it you wanted to raise your speed but have a speed cap and so on usually you do this by writing some variation of a max function and min function or a clamp function but you can just use a script that will automatically and consistently handle the same situation every time every time you want to make a number approach another number and not have it overshoot having a script like that saves you the mental energy of actually having to process which function the usual min max climb Voyageur which would be best while leaving your code easier to read and understand at a later date and it's something you can reuse all the time across lots of different projects because that's a very common problem to want to solve so I'm just going to go over a handful of scripts that I use across lots of different projects from that you might find as useful as I have I didn't write any of these scripts myself but you'll find actually a lot of them are used by lots and lots of different developers because they're just that useful they'll all be linked in the description so you can just copy them straight into your project normally I wouldn't recommend copying and pasting code from a tutorial video but in this case that's actually kind of the whole point it's that save you time and and brainpower so go for it go nuts that's what they're for now first up is approach and here it is this is basically what I was alluding to earlier when I was talking about taking a value and moving it towards another value this is literally what this does now this isn't a really a difficult thing to do in code right you can just use marks or men or clamp but this saves you having to worry about which one you want to stop those bits of code looking different one another and makes it very clear and readable into yourself when you're looking at your code later exactly what the bit of code does you give it a value a that you're changing and you give it the value that you want to approach B and then you give it the amount that you want to move towards it by so you can even move away from it by using a negative number or you can make be a negative number to go in the other direction like approach handles the direction of movement for you which is what makes it really really useful well an overshoot so after doing approach and say a step event you can always use something like if the value equals the value that you're moving towards you don't have to take less than or whatever or anything like that in case you have a shoe because you know you're not going to very very simple something you should know and this applies to kind of all of these script is the yeah calling a script in this way probably not the most efficient way but it kind of its kind of negligible to a very large degree the impact they're going to have calling a script to do sort of simple functions like this versus the gains from having much more readable code and much more easy to understand code when you come back to and you're trying to understand what on earth you did earlier right it can be really really helpful if you don't find you need to solve stuff then don't use it but from my experience in the experience of a lot of developers this stuff super super useful and totally worth the very very minor efficiency cost then you can always go back and refactor these things at a later date if you want to one of the thing that's quickly worth going over about these scriptures you'll see this section at the beginning of every one of these scripts this kind of triple-triple forward slash green common with the name of the script and a list of its parameters followed by the app program word you should definitely have this section at the beginning of every script you create yourself it's very very useful what it does is by having this here it defines the script to to GameMaker so then later when you're coding if you type the name of that script when you open you open brackets you'll get the autocomplete for the parameters for the arguments that you want to give that script so it'll treat it just like any other function you'll be able to see and remember exactly what each script requires you to give as arguments can be very very helpful now this one's one of my favorites for how robust and versatile it is and it's called wave what wave does is you give wave of two values and it will return a value that waves back and forth between those two values over a given time frame - so two set of wave lengths if you will for how long it takes for one wave to complete and then it just returns a value that alternates smoothly between those two values so you can use it to create a floating item or wavy text or really anything in your game that requires a value to just smoothly move between two values over time which is a lot more often than you might think and again just doing this by yourself is simple enough if you're very comfortable with sine waves and time and everything like that but being able to just call the script stops you having to think about it or remember how any of that works that super great super useful script they use this quite a lot next up is ramp no not that kind of wrap this color up that was a really bad joke I'm very sorry the way rap works is very similar to clamping that you give it a maximum and a minimum and it keeps the value between that Max and that minimum but instead of clamping so you put the number 12 in and your max is 10 instead of going back to 10 what it does is it wraps the value around so it comes back from the bottom again or comes back from the top if you went off the bottom so in the case where if you had a minimum of 0 and a maximum of 10 and your value was 12 your end value would be 2 because you would go up top and you would come back with 2 leftover can be very useful when working with angles new one things like go over 360 or stuff like that or any particular value that you want to wrap around in this fashion very useful next of this jump in direction I actually did write the script I wrote it today in about 5 seconds I'm surprised I've never used it before what it basically does is does what you would usually use length directs and length divider do which is move an instance in a particular direction by a given amount but instead of having to write two lines to move along the x axis and the y axis you can now just write one line and include the length and direction and it just makes it easier and cleaner to read and remember how it works what exactly that code is trying to achieve which is kind of the point of all of these last but not least this chance what chance does is you give it a number and it returns whether or not that number is greater than a random number between naught and one what this allows you to do is for example type if chance nor point seven and what you've written there is basically an if statement that will return true 70 percent of the time will return false 30% of the time gives you a really really easy way to create random chance based on a percentage now it's such a short line such a short script that maybe if you remember exactly how it works you can just type that each time you just type null point 3 greater than random 1 rather than calling chance as a script but because of how its scripts work it makes it really readable and really nice to look at and easy to understand when you type something like if chance nor point 3 it's really clear what that does so it's a view that's personal preference I quite like using the script adjust I have enough trouble trying to remember how my code works as is so every little helper I can get is a great help I am a huge fan and I guess an advocate of using helper script to keep your code as readable and understandable as possible for the longest possible time it's good to get into the habit of writing your own helper script so that you can reuse between projects for chunks of code that you just find yourself writing a lot they can save you a lot of time you slowly start to build up a toolset of different things that you can use to very quickly solve problems and allows you to get faster and faster and more effective at building games I also recommend checking out the website GML scripts calmness and useful gems on there as well that you might find useful for your own projects thanks guys I hope you enjoyed that one if you've got any scripts of your own that you think a really useful chunks of code that you reuse a lot between projects feel free to share them in the comments below developers sharing this stuff with one another over twitter is more or less how I discovered a lot of these different scripts I hope you found this one useful thank you very much watching and I'll see you guys next Friday with part 4 of the platformer series big extra showers to my patreon supporters without whom the video wouldn't have been made and without whom this topic wouldn't have been selected a voted for it and so it was made they'll also be voting on a topic of my next non platformer series video which will be the Friday after next big showers in particular two in a mules Charles Montgomery Dan Angel Rodriguez howls Guidry rocks on Jason McMillan and Owen Morgan thank you very much for your continued support and thank you of course for watching this video if you want to join my cool kids on patreon on the link in the description or probably over to the left about now just click on my face and it'll tell you what to do from there if you can't or you don't want to or whatever don't worry about it and I can't really make you do anything just a voice on the Internet thanks for watching guys see you next time
Info
Channel: Shaun Spalding
Views: 83,557
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Tutorial, GameMaker Tutorial, GameMaker, Game Development, Indie Games, Tutorial Series, Game Maker Studio, Making Games, How to make games, GameMaker Studio 2, GMS, GM
Id: 2FroAhEsuE8
Channel Id: undefined
Length: 9min 33sec (573 seconds)
Published: Fri Jul 28 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.