Big thank you to Josia for the tutorial. Find him on X: twitter.com/w7games In this tutorial learn how to code a save and load system into GameMaker. Implement: * Writing and reading variables as text files * Using structs & JSON * Saving and loading multiple objects / rooms * Using buffers
Nice timing. I had just finished FriendlyCosmonaut menu tutorials and needed a to learn how to save and load settings. Started looking for a save and load tutorial on this channel and on the website, and came across this video from 6 days ago that I completely missed. Nice one!
It was a simple and easy-to-understand tutorial on how to handle JSON and how to save and load files. However, this method has the problem that when instances are added to or deleted from a room, the save data becomes incompatible. I understand that to solve this problem, instead of deleting all instances and recreating them when loading, I need to use a method that reflects the saved contents without deleting the instances in the room. I'm looking forward to a tutorial that clearly explains this.
Best tutorial for understanding saving, loading, arrays, structs and using buffer. It finally all fell in place for me. Thank you ever so much for taking the time making it. 🤗
This tutorial is missing a few steps,. I wish this tutorial started from the very beginning with the development of the objects as well as the variables included in each object. The tutorial could also have been slowed down, its not a race. I spent so much time adding in a bunch of code, only for that code to be removed and then replaced with a different line of code. I did learn a few new things though, so I can't complain about that. I just really hope that there will be an updated/extended version of this tutorial that skips straight to the proper method as recommended in the video (using buffers).
If you have a very large game with tons of objects each with tons of variables, this video sort of reads like "how to create a beach with one grain of sand at a time." There's gotta be a faster more efficient way of saving the state of the game.
@@rooftoprumble7845 I eventually took a similar approach to the one in this video. However, I severely restricted when the player is allowed to save, so that it is done when very few interactions are occurring and very few instances are present. It's not how I originally wanted to do it (I originally wanted the player to be able to save at any time during gameplay), however for larger projects if a developer needs to track nearly every object, variable, array, alarm, data structure, etc. with perfect precision, then it can easily open the game up for serious bugs and crashes when saving is done at certain times. Even then, it's still an enormous amount of work. It seems to me that this should be functionality that is built into the engine itself. A save state, like a ROM emulator would do. Especially if you want to bill your engine as beginner-friendly, being able to easily save should be a no-brainer.
@@EtsaTwo Technically it's still there, however it's marked as deprecated and not recommended for use in the manual. The problem is that even then it was extremely limited and didn't save everything; your game needed to be very simplistic for it to be useful.
I've followed and triple checked everything in the video but I keep getting this error when hitting the save or load key. Variable .save_game(100030, -2147483648) not set before reading it. Any idea what the issue is here? I tried making the save_game and load_game functions isolated to their own scripts without declaring as a function and that seemed to work but then there appeared to be issues because they weren't in the same script. Seems like it is something related to functions.
So, I've been running into the exact same problem and couldn't for the life of me find what the problem was. Went to sleep, and it turns out I was an idiot : in the save_game() function within the script, I had typed : var _file = file_text_open_write(save.txt); instead of var _file = file_text_open_write("save.txt"); So basically your save.txt needs to be a string. If someone happens to have the same error, check that you haven't done the same mistake as me.
This is a bit hard to understand, as it's so fast, but I feel kind of challenged to understand it :D I just gonna watch it a few times more. But it's nicely done anyway ^^
Very good! One question, when exporting the game to Steam or another platform, if someone else takes the game with this .txt saving system and opens the file, will they be able to change the saved data? (examples: character level, upgrades, items, etc.)
Of course. But even if you encode it, if someone wish, he would probably find a way to hack save. What I learned - ignore it. If people wants to break they game after they paid for game - who cares.
It doesn't load the states of objects even though I followed this step by step. X and Y coordinations, image index and many other things don't work. It only loads the object's itself.
Очень крутые уроки, я перешел по ссылке от одного канала, на который я подписан, но там уже не выходят ролики. И я рад что перешел по ссылке, ведь попал на очень полезный канал, который мне сильно поможет в изучении программы.
Since this method works by deleting and recreating objects when loading a save, does that mean that the Instance Creation Code is no longer useable when using this method?
Great question. The best thing to do is to go onto the GameMaker Discord or Online Community Form and ask there. People are really helpful and usually someone is on hand to support
@@MachineMan64 I just made another seperate save and load script and used the first method in this video (so, without the for loop and manually loading each value)
I saved everything into an array: first global variables, then objects. Next, I access element 0 of the array, get the structure and set the values of the global variables. Then we can delete objects and create a loop, as in the lesson, but we start from the 1st element of the array, and not from the 0th.
After saving the game to save.txt the JSON viewer complains that there is an unknown character at the end of the file. I manually removed it (it was not visible, as pressing backspace once made no visible changes to the file), and it now works. But after saving again I get the same error. Does anyone know why? Here is the error: Expecting 'EOF', '}', ',', ']', got 'undefined'
Добавьте это как отдельную функцию Типа save() и load() И что бы это работало как например в Rpg Maker, там сохранения просто сохраняют ВООБЩЕ ВСЕ об игре, каждую переменную, положения персонажей, итд Это было бы очень круто >w
nvm i figured it out, the problem was cause i didn't save the x and y values for all objects, so when recreating them it gave an error. you need to save at least the x, y, and layer values for all objects if you plant to use them when creating the instance
Now I'm having a new problem, because the struct variables are set before the instances creation code is ran, after the loading is finished, the creation code for my objects runs and sets the variables back to 0
@@genyaarikado1778 I am having the same problem. What do you mean by setting the variables in the variable defenitions? In my create event I set all of my global variables. global.strength = 0;, global.speed = 0 etc. But then the struct wants these variables before the create event???!!! Jesus Christ
@@wizeller5040 All my variables are created when I start my game and the object is deleted and I save once you get in the game so the variables have been set
I started the tutorial and 2 minutes in it isn't doing ANYTHING when i press S, I thought that i would go ahead and download the project to see what I was doing wrong and when i opened it up and pressed S, it also didn't work there??? really confused at the moment, and I would appreciate some feedback
Hey Brett :). The best place to go for help is the GM community forum or Discord Forum: forum.gamemaker.io/index.php Discord: discord.com/invite/gamemaker
I appreciate the tutorial. However, at 6:20 this is not correct. The variables in Create event will still override the ones in the struct. The solution would be to use something like with(instance_create........) and then inside that with you would add every single variables hp = _struct.hp.... I made sure the variables in my save file is exactly the same as the one in object create event. But the information giving here is simply wrong.
@@boomgoesthedynamite69 That is one solution true. There is another I prefer more which is self[$ "hp"] ??= 100; When creating a new instance it would take the 100 value. However, when creating it using the struct, it would take the struct value. In other word, as long as hp is undefined during the create event, it will take 100. Otherwise, take the assigned value from any other source. Variables Definition for me is "not part" of the code. Hence, I prefer not to use it. But thank you anyway.
Good tutorial. Just a question: How to encrypt the data? As far as I know, the player can simply access the saved data and modify it. Is there any solution for it?
Maybe just let the player have access to it? Unless you are trying to protect an online multiplayer experience, it's actually monumentally frustrating when developers try to obfuscate / encrypt data from the end user. It means they don't have agency for their product that they paid for, and they can't fix issues on their end that the developer hasn't gotten around to fixing on their end .. or maybe never will. Imagine not being able to reset a bugged quest flag because the developer doesn't trust you with your purchase; or some sort of purity decision. Forget trying to mod the game for your own enjoyment.
Consider adding a function block and adding the code from the tutorial there. The rest of your project stays in Visual and you get to dip your toe into GML.
@@kiber_pivowar GameMaker exports are now free! From today :) * ruclips.net/user/shortstmejf5Zvupk?feature=shared * gamemaker.io/en/blog/gamemaker-free-platforms
Big thank you to Josia for the tutorial. Find him on X: twitter.com/w7games
In this tutorial learn how to code a save and load system into GameMaker. Implement:
* Writing and reading variables as text files
* Using structs & JSON
* Saving and loading multiple objects / rooms
* Using buffers
Nice timing. I had just finished FriendlyCosmonaut menu tutorials and needed a to learn how to save and load settings. Started looking for a save and load tutorial on this channel and on the website, and came across this video from 6 days ago that I completely missed. Nice one!
friendlycosmonaut has amazing tutorials!
What an excellent video. The progression from simple to complex situations was tremendously helpful, and you covered everything in under 12 minutes.
Big up Josia :)
Thank you.
You just turned the game I'm making and all my future games into proper games. 😀
It was a simple and easy-to-understand tutorial on how to handle JSON and how to save and load files.
However, this method has the problem that when instances are added to or deleted from a room, the save data becomes incompatible.
I understand that to solve this problem, instead of deleting all instances and recreating them when loading, I need to use a method that reflects the saved contents without deleting the instances in the room.
I'm looking forward to a tutorial that clearly explains this.
maybe post the problem on the gamemaker forum?
I always sucked at making saving and loading system 😅 Thanks! ❤
Best tutorial for understanding saving, loading, arrays, structs and using buffer. It finally all fell in place for me. Thank you ever so much for taking the time making it. 🤗
tysm! this was exactly what i was looking for!
Really appreciate these videos. Recently started using game maker and its an amazing toolset.
Wow, I just learned so much from this specific video. Very well done.
I really liked this tutorial . Thanks !
This tutorial is missing a few steps,. I wish this tutorial started from the very beginning with the development of the objects as well as the variables included in each object. The tutorial could also have been slowed down, its not a race. I spent so much time adding in a bunch of code, only for that code to be removed and then replaced with a different line of code. I did learn a few new things though, so I can't complain about that. I just really hope that there will be an updated/extended version of this tutorial that skips straight to the proper method as recommended in the video (using buffers).
Quick question, How do I find the save.txt in MAC :/
If you have a very large game with tons of objects each with tons of variables, this video sort of reads like "how to create a beach with one grain of sand at a time." There's gotta be a faster more efficient way of saving the state of the game.
Hey did you find out how to do it?
@@rooftoprumble7845 I eventually took a similar approach to the one in this video. However, I severely restricted when the player is allowed to save, so that it is done when very few interactions are occurring and very few instances are present. It's not how I originally wanted to do it (I originally wanted the player to be able to save at any time during gameplay), however for larger projects if a developer needs to track nearly every object, variable, array, alarm, data structure, etc. with perfect precision, then it can easily open the game up for serious bugs and crashes when saving is done at certain times. Even then, it's still an enormous amount of work.
It seems to me that this should be functionality that is built into the engine itself. A save state, like a ROM emulator would do. Especially if you want to bill your engine as beginner-friendly, being able to easily save should be a no-brainer.
@@svenjorgensen5it used to be built in.
@@EtsaTwo Technically it's still there, however it's marked as deprecated and not recommended for use in the manual. The problem is that even then it was extremely limited and didn't save everything; your game needed to be very simplistic for it to be useful.
I've followed and triple checked everything in the video but I keep getting this error when hitting the save or load key. Variable .save_game(100030, -2147483648) not set before reading it. Any idea what the issue is here? I tried making the save_game and load_game functions isolated to their own scripts without declaring as a function and that seemed to work but then there appeared to be issues because they weren't in the same script. Seems like it is something related to functions.
So, I've been running into the exact same problem and couldn't for the life of me find what the problem was. Went to sleep, and it turns out I was an idiot : in the save_game() function within the script, I had typed :
var _file = file_text_open_write(save.txt); instead of var _file = file_text_open_write("save.txt");
So basically your save.txt needs to be a string. If someone happens to have the same error, check that you haven't done the same mistake as me.
This is a bit hard to understand, as it's so fast, but I feel kind of challenged to understand it :D I just gonna watch it a few times more. But it's nicely done anyway ^^
Basically, if we need to save and load for console?
We need to use the async version and what are the differences from console to console?
Thank you!
The best place to go for help is the GM community forum or Discord
Forum: forum.gamemaker.io/index.php
Discord: discord.com/invite/gamemaker
Very good!
One question, when exporting the game to Steam or another platform, if someone else takes the game with this .txt saving system and opens the file, will they be able to change the saved data? (examples: character level, upgrades, items, etc.)
Of course. But even if you encode it, if someone wish, he would probably find a way to hack save. What I learned - ignore it. If people wants to break they game after they paid for game - who cares.
It doesn't load the states of objects even though I followed this step by step. X and Y coordinations, image index and many other things don't work. It only loads the object's itself.
My god the pacing is PERFECT. Thank you for this
Очень крутые уроки, я перешел по ссылке от одного канала, на который я подписан, но там уже не выходят ролики. И я рад что перешел по ссылке, ведь попал на очень полезный канал, который мне сильно поможет в изучении программы.
Since this method works by deleting and recreating objects when loading a save, does that mean that the Instance Creation Code is no longer useable when using this method?
Hi all, will this solution work for adding save/load game function in GM 1.4999 ?
How should i save values in the array that are not variables? such as room seeds and globals?
Great question. The best thing to do is to go onto the GameMaker Discord or Online Community Form and ask there. People are really helpful and usually someone is on hand to support
I'm having this exact issue, please let me know if you've figured it out.
@@MachineMan64 I just made another seperate save and load script and used the first method in this video (so, without the for loop and manually loading each value)
I saved everything into an array: first global variables, then objects.
Next, I access element 0 of the array, get the structure and set the values of the global variables.
Then we can delete objects and create a loop, as in the lesson, but we start from the 1st element of the array, and not from the 0th.
@GameMakerEngine Please make a Tutorial about Resolution and how to debug in not fullscreen but have to viewport set to 1920x1080 and so on
After saving the game to save.txt the JSON viewer complains that there is an unknown character at the end of the file. I manually removed it (it was not visible, as pressing backspace once made no visible changes to the file), and it now works. But after saving again I get the same error. Does anyone know why?
Here is the error:
Expecting 'EOF', '}', ',', ']', got 'undefined'
Добавьте это как отдельную функцию
Типа save() и load()
И что бы это работало как например в Rpg Maker, там сохранения просто сохраняют ВООБЩЕ ВСЕ об игре, каждую переменную, положения персонажей, итд
Это было бы очень круто >w
I'm getting the error or when trying to create the instance during loading
nvm i figured it out, the problem was cause i didn't save the x and y values for all objects, so when recreating them it gave an error. you need to save at least the x, y, and layer values for all objects if you plant to use them when creating the instance
Now I'm having a new problem, because the struct variables are set before the instances creation code is ran, after the loading is finished, the creation code for my objects runs and sets the variables back to 0
Fixed this by setting the variables in the variable definitions instead of the create event
@@genyaarikado1778 I am having the same problem. What do you mean by setting the variables in the variable defenitions? In my create event I set all of my global variables. global.strength = 0;, global.speed = 0 etc. But then the struct wants these variables before the create event???!!! Jesus Christ
@@wizeller5040 All my variables are created when I start my game and the object is deleted and I save once you get in the game so the variables have been set
I started the tutorial and 2 minutes in it isn't doing ANYTHING when i press S, I thought that i would go ahead and download the project to see what I was doing wrong and when i opened it up and pressed S, it also didn't work there??? really confused at the moment, and I would appreciate some feedback
Hey Brett :). The best place to go for help is the GM community forum or Discord
Forum: forum.gamemaker.io/index.php
Discord: discord.com/invite/gamemaker
for some reason i can't load the save file from a title menu, how do i implement that
i want to be able to save the game somewhere and load at that point where i saved when i resume the game in the menu
I appreciate the tutorial. However, at 6:20 this is not correct. The variables in Create event will still override the ones in the struct. The solution would be to use something like with(instance_create........) and then inside that with you would add every single variables hp = _struct.hp....
I made sure the variables in my save file is exactly the same as the one in object create event. But the information giving here is simply wrong.
Thank you. I'm lucky you posted this only 2 days ago.
much better solution is to set these variables using the Variables Definition tab, since passing in a struct runs after these are set
@@boomgoesthedynamite69 That is one solution true. There is another I prefer more which is self[$ "hp"] ??= 100; When creating a new instance it would take the 100 value. However, when creating it using the struct, it would take the struct value. In other word, as long as hp is undefined during the create event, it will take 100. Otherwise, take the assigned value from any other source.
Variables Definition for me is "not part" of the code. Hence, I prefer not to use it. But thank you anyway.
How would you delete a save file as a option
I think you would have to use some code that just deletes the file from your computer. Google it probably tho
9:36 dont u have to use is_undefined?
No, both should work.
Good tutorial. Just a question: How to encrypt the data? As far as I know, the player can simply access the saved data and modify it. Is there any solution for it?
Maybe just let the player have access to it?
Unless you are trying to protect an online multiplayer experience, it's actually monumentally frustrating when developers try to obfuscate / encrypt data from the end user. It means they don't have agency for their product that they paid for, and they can't fix issues on their end that the developer hasn't gotten around to fixing on their end .. or maybe never will.
Imagine not being able to reset a bugged quest flag because the developer doesn't trust you with your purchase; or some sort of purity decision. Forget trying to mod the game for your own enjoyment.
i use visual how will i do
Consider adding a function block and adding the code from the tutorial there. The rest of your project stays in Visual and you get to dip your toe into GML.
How can i make mobile game without purchasing 70$ bundle?
Its not for the commercial use, i cant give so much money just for 1 game
@@kiber_pivowar GameMaker exports are now free! From today :)
* ruclips.net/user/shortstmejf5Zvupk?feature=shared
* gamemaker.io/en/blog/gamemaker-free-platforms
For some reason my saved data is in chineese
haha I wish I had that problem.
top!
for some reason, when following this, I was not able to correctly load variables (they are saving correctly but do not reflect or update).
that sucks