Gamemaker Studio 2 Save & Load Text Files (Save System)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to today's tutorial my name is joseph i hope everyone's doing well today so in today's video i'll be covering a simple save and load um to text file tutorial this will allow you to save things export things um for your game on pc so before i get into that i want to thank everyone for the channel you guys are all amazing um you guys are really helping drive things forward and i have to really thank you guys you have no clue so let's get into this video so save and load systems are a pain in the ass i've just spent the past extra half an hour debugging this code because i found something really dumb i had to fix so what does what is it and how does it work the basic idea is any game you play you create a save file and yeah it basically puts critical data in there so in this tutorial i'll be just showing you some basic read write applications you can do with it um so the first things first when we write the code you can see i've got a load save i've set up a room and i've just got two sprites just nothing fancy you guys should be expecting that by now so we'll look at the save function first which is the first part of the code i wrote and it's going to look a little overwhelming but it's not too bad once you understand what it's doing i need a save id for my save file which i've just created as a temporary value because i'm not needing this critical information you can set this to be a more permanent variable but i don't really see a need line count is massively important because it keeps track of how many lines there are in your program or in your save file more importantly allowing you to work out where to reference and how to get files back so basically the first step is we open a file and i've just called this text the first line i write is i just write a text or a string called oy just so i know it's working and then i add one to my line count then the line count is equal to itself plus a random value of 20 to 100 or a thousand i then write the line count to the save file adding one to itself as well to account for its own writing the next step is actually generate a bunch of x and y coordinates based on room height and width and the last thing i do is i close my say or my file because otherwise i'll generate memory leaks you'll also notice throughout the file i've got these um writings which just basically means drop down a line the other thing to bear in mind is you have to be specific when writing a string and when writing a value a value is read as real a string is read as a string so it's important to know that distinction so now looking at that you're going to say well what's the point of this like it looks pretty straightforward so when i run the program how do i know if it works so if i hit the save key right now you're not going to see anything and if i hit the load key i'm just going to get an error and that's because i've got no safety to protect against if the file doesn't exist but that does tell us something it tells us the file doesn't exist so if i pull this over here you guys are going to see that i've got this random location my computer c drive users app data local and then my game maker save slash load so if i hit the save key now you're going to see it's going to generate me a file and you can see the file's got size it's 15 kilobytes big and if i boot that up you're going to see a bunch of random information dumped into it so you'll see in the logic here that we've used my first step is i've written oy i know that because i've written that next i've got a line count so i know there's 726 lines this end number should always be even because i'm writing two values if i'm writing one value it'll be odd um oh no sorry i lie because i've also got oy there it's just coincidental that i've got a pairing but yeah so bear in mind you should know roughly how many lines you should be writing otherwise things can get a bit painful so the load function is basically the reverse so if i load my load function up to show you guys you're gonna see that i've got three steps in here i've got an array controller i've got a star account which just controls the array so it just remembers how many i've got so my first step is as other than the usual check for id when clicking is i load the file and i do a line count as temporary values and i reset my star count so that just resets the bases for the program next step is i do a load file same as before i load my text file i actually ignore my first testing string just to make sure things worked because i don't need to load oi into the program i'm just making sure it worked next i do a reading line so you see this is different so instead of a writing it's a reading and basically i continue to reference the load function i then read the line so you can see how this is different from the save where i'm actually just pulling whatever on that line is into this value i then read in another line i then start my array generation so i basically generate all my new stars in the system and then i resize my array i didn't actually even know this function existed until today because this is what caused me some havoc before i resize my array into an x and y to the same sizes as my star account so it trims any extra entries and then i close the file again if you don't close you'll create memory leaks under the draw function i draw itself or i draw the button that again stumped me today because i was working through i was like why am i not drawing my object that would be why remember to draw self um and then i just run a simple for loop with all the entries so if i rely rerun the program and now i can hit load so you'll see here i've still got this data right so if i hit load it loads straight in and if i go save because now it's going to regenerate it should regenerate different stars but what about if i edit the program so if i go through here and let's just get rid of all of this let's say i've got four lines and i start at 30 30 100 100 300 300 600 600 and save so oops sorry that should be eight lines so that's one two three four five six seven eight nine ten sorry ten lines save and let's go load let's see what happens i'll either break this or work hey look at that so i've got all my stars now on a random line so that's a load save system it's pretty straightforward i hope it helps you guys out if you have any questions feel free to ask these things can be a bit a bit complicated and i have done some quite advanced things with these in the past um one of the things you might want to look at is adding some slight level of encryption to prevent players from getting into your save files and rooting around and changing stats they shouldn't have access to but i hope you guys stay safe have a great day and i'll talk to you guys later you
Info
Channel: Domain Studio
Views: 221
Rating: undefined out of 5
Keywords: Gamemaker, Studio, tutorial, GUI, Programing, Easy, Help, GMS, If, File, Text, Save, Load
Id: bCxGuLfV4qA
Channel Id: undefined
Length: 8min 20sec (500 seconds)
Published: Fri Nov 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.