You can also encrypt and compress buffers, that's why they're so great for saving data! Let me know what you thought of this video, and if you have video suggestions/requests, do comment!
Excellent as always!! I love how clear and structured your videos are, no waffle/fluff, straight to the good stuff, amazing! Thank you so much Matharoo.
I rarely leave comments on youtube but I have to give credit where credit is due. For someone like me who has development background but new to GM2 simple googling for answers usually brings a lot of stuff that is based on older techniques, which may lead you to a rabbit hole. I like JSON but I was under the impression that the only way to save/load data in GM was by using maps and grids and I was very relieved to find this video. I have found that whenever i had a question and googled for answers for GM2, your tutorials were often the ones I ended up watching. People often forget that technology changes rapidly so often times a tutorial from 4-5 years ago might well be obsolete now. Thanks!
Thank you actually explaining what JSON is, instead of just assuming we know. I'm so freakin' tired of Game Maker videos talking to me like I got a degree in computer science a few years back. I use Game Maker for a reason! I wanna spend more time being creative and less time thinking about numbers. Thank you.
That is the reason why I was so late to the JSON party. Everyone kept saying "use JSON, you should; hMmm" but no one explained what it was or why it was so good. So while making this video I felt that there were others who had probably heard of JSON but did not know what it meant, so the explanation was necessary. Thanks for your support 😊
Shaun Spalding: *making json saving tutorial* Matharoo after two hours: *also making json saving tutorial* *Meme about a guy who follows a girl, but he is stopped by another guy*
If you just save the struct as it is at runtime, then only the DS IDs will be saved but the data inside them will not be serialized at all. You don't have to convert the maps and lists to structs and arrays though - use ds_map_write and ds_list_write to serialize the data as a string and save that into the struct/array before converting to JSON. Use ds_map_read and ds_list_read to convert them back to DS after loading. manual.yoyogames.com/GameMaker_Language/GML_Reference/Data_Structures/DS_Maps/ds_map_write.htm manual.yoyogames.com/GameMaker_Language/GML_Reference/Data_Structures/DS_Lists/ds_list_write.htm
hello, I would like to learn how to do to have a fisherman on the boat, have the sea with the fish below going side to side appearing random, and with this fisherman with the arrows I can increase and decrease the fishing rod line and catch the fish with hook and pull the boat, can you explain?
Nice video! How would this be implemented when changing rooms? For example, if I have opened chests and enemies in prior room, how would that data be saved?
@@GameMakerStation Thanks for responding! I actually saw this before. What I don't understand is how to save specific object variables and numbers, data, etc that can be loaded once the game is quit. This link looks like just room persistence using code but I don't understand how this would be saved to a file and then loaded after the person quits the game.
It is! JSON is one of those things that's easy to understand but sadly isn't as widely used as it should be, within the beginner community. These new functions for Structs are really going to help, and make it easier for beginners to use the power of JSON!
If you are really 21, congrats! When I was that age all I knew was how to down a 12 pack of beer and still get into a bar. And how to do donuts with a diesel forklift.
I have added updates to cover any changes that can cause confusion in students, though I have not implemented new features (such as structs, Sequences, etc.) because the course is essentially based on v2.2, and I'm working on a new course for v2.3+. That said, the course is still relevant if you want to make a crafting game, and a lot of people are getting and learning from the course even after the v2.3 update. I am also always available for support, should you face any issues. If you decide to get it, please use my referral link as Udemy takes a smaller cut from these purchases: www.udemy.com/course/crafting/?referralCode=81153850CB978F6D9ECC Thanks!
Just to make rooms "persistent", I'd store the saved data for each room's instances in a global struct. Look out for my next tech blog on the YoYo Games site, it will have an answer to your question.
stringify doesn't handle methods! my methods attached to my structs are lost in this process and it really ruins my strategy. could you mention a workaround for this?
When you save the struct, save the name of the struct's constructor (think you can get that by running instanceof() on it) and when you load the struct, find the constructor using asset_get_index() and then new() it. You can then apply data from your loaded struct into that new struct and that way you will get a struct with your loaded data and all relevant methods.
@@GameMakerStation thank you so much for the quick reply and the nice strategy! so far I have it working where I can create a new struct, but I'm struggling a bit to take the methods from the new struct and attach them to the old. (hour later) I think I just got it
Informative video with great editing, but is it possible to save global variables? All the tutorials I've seen on JSON structs and arrays in GameMaker only save local variables. I tried saving global variables but it doesn't seem to be working. Do you have any tips on how to save global variables?
@@GameMakerStation Well, I tried to make an array to save my players health and position with this code: var _saveData = array_create(0); with (obj_player) { var _saveEntity = { obj : object_get_name(object_index), y : y, x : x, health : global.hero_health, } array_push(_saveData, _saveEntity); } var _string = json_stringify(_saveData); var _buffer = buffer_create(string_byte_length(_string) +1, buffer_fixed, 1); buffer_write( _buffer, buffer_string, _string); buffer_save ( _buffer, "savedgame.save"); buffer_delete( _buffer); show_debug_message("Game saved! " + _string); But it didn't seem to work. It saves the player's position, but not the health. I think I'm doing something wrong in the syntax but I'm so new to JSON that I have no idea what.
Ok, so what do I do with all the other data structures? Stop using them? Convert every single one into a struct or array? I should just be able to tell something all the data I want to save and it happens (whether built into GMS or something custom). There's just a lot of questions left open here.
No need to stop using other data structures if you're already using them in your systems. It's just about knowing what works best for what you are doing.
It would have been helpful if you let us know how to save lists/maps etc at the end of the video, instead of telling us this method won't work for it, so we are screwed.
The whole point of this video was that structs and arrays could now be saved as JSON and you wouldn't have to use lists and maps anymore. For them please use json_encode() and json_decode(), they do the same thing as stringify and parse but are made for maps and lists.
You can also encrypt and compress buffers, that's why they're so great for saving data!
Let me know what you thought of this video, and if you have video suggestions/requests, do comment!
Excellent as always!! I love how clear and structured your videos are, no waffle/fluff, straight to the good stuff, amazing! Thank you so much Matharoo.
I got the saving/loading down. Is there a tutorial or a guide showing how to encrypt buffers anywhere?
I rarely leave comments on youtube but I have to give credit where credit is due. For someone like me who has development background but new to GM2 simple googling for answers usually brings a lot of stuff that is based on older techniques, which may lead you to a rabbit hole. I like JSON but I was under the impression that the only way to save/load data in GM was by using maps and grids and I was very relieved to find this video. I have found that whenever i had a question and googled for answers for GM2, your tutorials were often the ones I ended up watching. People often forget that technology changes rapidly so often times a tutorial from 4-5 years ago might well be obsolete now. Thanks!
Thank you actually explaining what JSON is, instead of just assuming we know.
I'm so freakin' tired of Game Maker videos talking to me like I got a degree in computer science a few years back.
I use Game Maker for a reason! I wanna spend more time being creative and less time thinking about numbers.
Thank you.
That is the reason why I was so late to the JSON party. Everyone kept saying "use JSON, you should; hMmm" but no one explained what it was or why it was so good. So while making this video I felt that there were others who had probably heard of JSON but did not know what it meant, so the explanation was necessary.
Thanks for your support 😊
This is the best basic save and load tutorial, you explain things in a brief clear way which makes it much easier to understand
Shaun Spalding: *making json saving tutorial*
Matharoo after two hours: *also making json saving tutorial*
*Meme about a guy who follows a girl, but he is stopped by another guy*
Oh wow.
Thanks, Matharoo. Great video! I'm glad I'm getting into GMS 2 when all of these great updates are coming out.
Hi there, isn't JSON editable ? Players will be able to "cheat" modfying the json data right ?
This is amazing, good job!
How would one handle the case of writing ds_lists and ds_maps that are nested within a struct to json? Must they be converted to arrays?
If you just save the struct as it is at runtime, then only the DS IDs will be saved but the data inside them will not be serialized at all. You don't have to convert the maps and lists to structs and arrays though - use ds_map_write and ds_list_write to serialize the data as a string and save that into the struct/array before converting to JSON. Use ds_map_read and ds_list_read to convert them back to DS after loading.
manual.yoyogames.com/GameMaker_Language/GML_Reference/Data_Structures/DS_Maps/ds_map_write.htm
manual.yoyogames.com/GameMaker_Language/GML_Reference/Data_Structures/DS_Lists/ds_list_write.htm
@@GameMakerStation Elegant solution. Thank you for the detailed reply!
hello, I would like to learn how to do to have a fisherman on the boat, have the sea with the fish below going side to side appearing random, and with this fisherman with the arrows I can increase and decrease the fishing rod line and catch the fish with hook and pull the boat, can you explain?
Math, you helped me a LOT with this tutorial, mate! Big thanks to you! =D
is there any way to save and load on game end and game start?
Nice video! How would this be implemented when changing rooms? For example, if I have opened chests and enemies in prior room, how would that data be saved?
See this: www.yoyogames.com/en/blog/multiple-levels-tutorial
@@GameMakerStation Thanks for responding! I actually saw this before. What I don't understand is how to save specific object variables and numbers, data, etc that can be loaded once the game is quit. This link looks like just room persistence using code but I don't understand how this would be saved to a file and then loaded after the person quits the game.
Meaning across many rooms; not just the current one.
Thx bro this vid rly helped
Btw first and uhh the concept of JSON is actually rly ez
It is! JSON is one of those things that's easy to understand but sadly isn't as widely used as it should be, within the beginner community. These new functions for Structs are really going to help, and make it easier for beginners to use the power of JSON!
What type of file does this save it as? Is it a txt file?
If you are really 21, congrats! When I was that age all I knew was how to down a 12 pack of beer and still get into a bar. And how to do donuts with a diesel forklift.
Is it possible to save global variables?
Hey Matharoo, is your udemy course up to date with the new stuff in GM 2.3? I'm thinking in buying it.
I have added updates to cover any changes that can cause confusion in students, though I have not implemented new features (such as structs, Sequences, etc.) because the course is essentially based on v2.2, and I'm working on a new course for v2.3+. That said, the course is still relevant if you want to make a crafting game, and a lot of people are getting and learning from the course even after the v2.3 update. I am also always available for support, should you face any issues.
If you decide to get it, please use my referral link as Udemy takes a smaller cut from these purchases: www.udemy.com/course/crafting/?referralCode=81153850CB978F6D9ECC
Thanks!
how would you implement this system in a game with more then one room?
Just to make rooms "persistent", I'd store the saved data for each room's instances in a global struct. Look out for my next tech blog on the YoYo Games site, it will have an answer to your question.
Finally! Proper JSON support! 😭 Great video!
stringify doesn't handle methods! my methods attached to my structs are lost in this process and it really ruins my strategy. could you mention a workaround for this?
When you save the struct, save the name of the struct's constructor (think you can get that by running instanceof() on it) and when you load the struct, find the constructor using asset_get_index() and then new() it. You can then apply data from your loaded struct into that new struct and that way you will get a struct with your loaded data and all relevant methods.
@@GameMakerStation thank you so much for the quick reply and the nice strategy! so far I have it working where I can create a new struct, but I'm struggling a bit to take the methods from the new struct and attach them to the old. (hour later) I think I just got it
Informative video with great editing, but is it possible to save global variables? All the tutorials I've seen on JSON structs and arrays in GameMaker only save local variables. I tried saving global variables but it doesn't seem to be working. Do you have any tips on how to save global variables?
Sure, you can do that. Variables are simply references to values anyway, so how you get them shouldn't be an issue. What's the problem here?
@@GameMakerStation
Well, I tried to make an array to save my players health and position with this code:
var _saveData = array_create(0);
with (obj_player)
{
var _saveEntity =
{
obj : object_get_name(object_index),
y : y,
x : x,
health : global.hero_health,
}
array_push(_saveData, _saveEntity);
}
var _string = json_stringify(_saveData);
var _buffer = buffer_create(string_byte_length(_string) +1, buffer_fixed, 1);
buffer_write( _buffer, buffer_string, _string);
buffer_save ( _buffer, "savedgame.save");
buffer_delete( _buffer);
show_debug_message("Game saved! " + _string);
But it didn't seem to work. It saves the player's position, but not the health. I think I'm doing something wrong in the syntax but I'm so new to JSON that I have no idea what.
Ok, so what do I do with all the other data structures? Stop using them? Convert every single one into a struct or array? I should just be able to tell something all the data I want to save and it happens (whether built into GMS or something custom). There's just a lot of questions left open here.
No need to stop using other data structures if you're already using them in your systems. It's just about knowing what works best for what you are doing.
It would have been helpful if you let us know how to save lists/maps etc at the end of the video, instead of telling us this method won't work for it, so we are screwed.
The whole point of this video was that structs and arrays could now be saved as JSON and you wouldn't have to use lists and maps anymore. For them please use json_encode() and json_decode(), they do the same thing as stringify and parse but are made for maps and lists.
Still in beta >_
Shouldn't be long till it drops into stable.
Good tutorial. I'll be waiting for 2.3.1.
I also got to know some functions I didn't know yet like ```find_instance``` .