I dont know anything about to save data in JSON files but Im here learning a lot, although there is another and updated tutorial. I´ll watch after this one of here.
thank you soo much for your video, you cannot imagine how elegant is the loading/saving thanks to this code. I even extended the code so that I save game variables (in a map) and inventory list (in a list) and enemies locations and types (in a map within a list, like what you did) and finally the whole thing in one big wrapper map ^____^
You should make an online multiplayer tutorial! There aren't many Game Maker tutorials out there that cover the subject (not to mention effectively, or completely), and I feel like you could make an effective tutorial. Not only that but the Game Maker community for both GMS1 and 2 would benefit as a whole. I've been watching your tutorials for a few years now, and I would definitely want to see this!
The problem with online multiplayer is that it exceeds game maker itself. Sure you could set up clients ready for playing multiplayer but the networking solutions would need to be done outside Game Maker and would involve the use of networking knowledge as well as money to set up the infrastructure (servers) even if you plan on peer to peer you still need hole punching servers. LAN however is easily possible and it is easily found on the internet for GMS2/GMS1.4 but it isn't online multiplayer
Getting everyone to port forward their router is a terrible idea for a commercial game, there would need to be some kind of server connect clients together using udp hole punching so people don't have to do that. (and that's just for peer to peer, not even touching on dedicated servers)
Say you release a game on Steam (also for the purpose of your argument you're not using Steam's mediation server for peer to peer, and are just using GM's network functions.) It's a 4 player rogue-like (the most common kind of game for indie devs.) They want to play multiplayer together but before buying the game have no idea what port forwarding is let alone that this game needs it to function. They press host and get a nice prompt saying ("Please port forward ports xyz on your router.") the friends who aren't hosting are fine but 1 out of 4 people will still need to go through port forwarding, which is highly unprofessional. You'd see refunds from people saying the game is broken because you're expecting players to have networking knowledge.
If you're talking about everybody (possibly thousands of players) connecting to a dedicated server made in game maker then yes, only one machine needs to have their connected router port forwarded but game maker wasn't designed to make dedicated server programs with: GM made games only run on a single core meaning there is no multi threading (something servers generally require, especially logic/ packet heavy game servers). I'm pretty sure I've read somewhere game maker networking fizzles out at sub-50 connected clients. Lol, I don't mean to be a contrarian, if that's how it comes off.
@@AurrenTV Well I made an Online Multiplay Shoot 'em Up for my class mates and me to play. Had an in-game lobby, fluid ping and worked really good as a whole. And I only needed Hamachi for it to work! In my opinion all is right what you say except the part "The problem with online multiplayer is that it exceeds game maker itself." I managed to do alot with GameMaker only, and simply buying a server or needing to pay for the sake of programming a game should be obvious beforehand and has nothing to do with GameMaker itself. You could say the same things for Unity or UnrealEngine in terms of Online Multiplayer therefore it makes no sense to say that GameMaker can't come up with good-enough networking solutions. I mean I even amde a voice-chat through GM Networking ^^
I have been doing this list in a map with list thing in my game and didnt even know i could save it all into a JSON . Thx Also i came here after your brief explanation you did when building your game for Ludum Dare 47.
Thanks for a tutorial on this I can follow. I do think Game Maker could make this all so much simpler they seem to have compleatly droped to ball on there usual ethos of making everthing very accessable when it comes to saving.
Hey man I really like your tutorials and find them very useful! I could not be more thankful. Unfortunately, I would like to ask you a question about this one because I didn't get it very clear. So the question is: if i want to add another map/list inside the root list just to have, for example, a map for keys data and a map for enemies data. When "adding" it to the root list, in the "ds_list_mark_as_map" function, should I still reference the position to be listed as "ds_list_size -1"? I mean, would it still be listed correctly?
Great tutorial! Say I have a persistent object, obj_controller that creates global variables for my game. Would I save that instance and its attributes (like how you did with x,y,sprite,etc..) and then load them into the game or should I create a new key-value pair in the ds_map and save/load that way?
I'm brand new to GML (though already a professional software dev) and saving content from my little demo GML projects has been the worst part of any of them. This seems a nice method, and JSON is a dirt simple format to work with. I'll be sure to give this a whirl when I can. :) Though, rather than character/string data and expensive JSON processing, could a method similar to this save raw byte data to disk? It'd effectively be a memory dump stored as a map or tree. Just two points in the video that I think need a bit of clarification: 15:00 Compatibility isn't the reason to use a buffer. Buffers are sequential data held in a temporary portion of memory. A storage device (like an SSD) is slower than RAMs, o you create a buffer for the disk to read at it's own pace, rather than sending chunks of data to the disk and waiting for said chunk to complete it's read or write operation before sending another. Buffers are more complicated to write in a high level language, but more performant since it's actually simpler to implement under the skin; there's less obfuscation with how a computer actually works. 21:08 It's just called the Vertical Bar, but in computing it's more commonly refereed to as the "Pipe" character because of it's association with the UNIX Pipeline. It's not to be confused with the broken bar ( ¦ ) which is AltGr + Grave Accent ( ` ) key on British keyboards. My nitpicking aside, great video! I'll try to use these techniques somewhere down the line. :)
@@benanderson89 Hello from Cumbria; I was hoping someone could answer a quick question I have on this subject, but can't find an answer. I would consider myself a beginner but have been using GameMaker studio and learning about computers for 2 decades. By using JSON to save game progress / variables and what not; Would this be the best method for my intended target which is HTML5, rendered in JavaScript? which should make this method work more natively? One thing I have noticed with HTML5 is some events appear to be getting read from right to left making the usual windows platform logic go out the window and I have to use alternative measures to achieve similar results.
I did everything the same in the video, but now when I save and load the game, the player duplicates. In other words, one player remains as I saved, and the other reverts back to the beginning of the game. What should I do?
so i have alot of rooms(i was following your tutorial shaun), in the save file i also put the room in which i am currently, but when i load it the enemies i killed are still there and alive(i did save their hp) can anyone help me please edit: instead of using a object i put the code in 2 scripts (loading and saving) don't know if that makes a big difference i need it to be in a script so that i can call it in my menu
If anybody else cannot find where GMS2 is saving your files, drop this code in just after your save. It will pop up the directory where files are being saved in a dialogue box when you run your game. You can then remove the code from your game once you've found the file. file_text_close(file_text_open_write("temp")) // opens and closes a temporary text file var r=filename_path("temp"); // creates a temporary variable with the filepath for that file file_delete("temp"); // deletes that file show_message (string(r)); // display a message with that file directory file_text_close(_file); // closes the file to prevent memory leak Don't leave this in your final game, obviously.
I don't know if this will help, but it works for me after much pain and suffering trying to get it working in the first place. For the loading, I had to make his load file script in the video that loads the buffer (for buffers, when it's numbers you're using use one of the buffer number ranges constants in the game maker manual, BUT if you're using text (string) then use buffer_string...this stumped me for ages since gamemaker kept saying "buffer out of range, going back to 0" and I couldn't find any guides). Then you wanna do some stuff like... //checks if file exists first (don't worry about name or "dat" that's just related to my game) "if (file_exists("XGA.SAVEFILE.dat")) { var _map_decoded = LoadJSONFromFile("XGA.SAVEFILE.dat") var list = ds_map_find_value(_map_decoded,"ROOT")
var size = ds_list_size(list) //loops through whole ds list containing all the ds maps on each list part (I think?) for (var i = 0; i < size; i++) { var listvalue = ds_list_find_value(list,i)
global.variable you want to change or whatever = ds_map_find_value(listvalue, key) Where "key" is whatever you set it to be when you saved your game using ds_maps beforehand. ..... } Then you destroy the list and ds map to prevent a memory leak Hope this helps...even though it's over 6 bloody months ago 😂
Dinar 87 I’m having the same problem when I load my game: Illegal buffer index -1, obviously you wrote this a while back but I’m a little confused about how you fixed this issue?
I've seen this type of tutorial a couple of times from different YTbers. And the one thing that none of them show is saving objects that have lists/maps tied to their instances. They all say it can be done but none of them show it. Could you please give or show an example of saving/loading objects that have lists of other objects tied to them. EXAMPLE: In obj_player there is a variable that stores the id of another object; obj_inventory. obj_inventory is an object that stores a ds_list. In that ds_list is a bunch of instance id's of items the player is holding. How would you set this up for save/load?
Well, I would definetly *not* create inventory system based on instances in first place, that's for sure. I would asign a number to each type of item as an enum and then I would save in a ds_list or ds_map ids of items. Because in all honesy, instance id are "tempoary".
Nice tutorial, you really help me with this but still a have one problem, I made platform game and when I tried load game nothing happend well first i screw up few details in code but i fix it immidiatly..
What do I do if I want to add more things to a struct, but there is already a save file that doesn't have the new variables in the json file? How do I avoid the game crashing? This would be very important for if I were to publish to steam and need to update the game.
How does one deal with saving objects with different attributes. For example a car object has speed, fuel, color. A robot has weapon strength, durability, etc. Do I need different parent SaveMe objects for each type of object, then a new with() statement for each object type? And how do I load the different types of objects in the load event?
Same problem here. I have a game in which you pick your side, the player has levels xp and upgrades, there's 9 worlds and each has 5 levels, it's teritorry based, I wont get into the details of it. Basically there's a lot of very important stuff going on Juju Adams and Shaun both say this code is very flexible and I'm sure it is, but having to write lines for saving and loading for pretty much EVERYTHING just seems like a bad practice. Yes, you could say that I don't need everything saved, but yes, yes I do (atleast it seems like I do). Not sure how to do this properly, I've watched Jujus talk and they don't explain how to properly use it. I understand the code, they both explain it very well but I am not sure how to use it properly.
You Would Put It In Front Of The Line Of Code, Let's Say We Are Using Jumps, if No Other Object Had It You would Put: with (Obj_Player) ds_map_add(_map,"jumps",jumps);
Okay i figured out how, but it’d be hard to explain over youtube comments If you haven’t figured it out already, do you have discord? I can explain it there
I popped this video open because i was annoyed at how Game Maker’s native function ds_map_secure_save encrypts per device. I want to still be able to save data that can only be read by Game Maker when it loads, but not readable by a human. Essentially i want to have non-tamperable save data that i can move from machine to machine. Pardon this question but because the video is 30min long, i wanted to ask before i watched if it solves the problem i posed above. Thank you in advance.
This is a great video, Shaun, well put together and easy to follow. However it has a major flaw, in that you simply cannot guess for all of the variables which may or may not be present in all objects at any point in the game. You see I was able to save all of the variables to the .sav file using the VARIABLE_INSTANCE_GET_NAMES function within the code. This allowed me to store any data, regardless of the object and it's variables. Storing and saving works fine this way, I can see the data is present in the file. However your method doesn't seem to be able to pull the data out. You claim that this is more advanced than a simple text file however I still find myself having to list every possible variable at any given time, which is just not viable if you want to save the state of the game mid-battle, for example.
I'm not too sure about this... but I think in your case maybe just creating global variables to check where in they game you are? Then just save those variables as strings like in this vid. Load them upon file selection. Adjust code accordingly to them? My two cents
First make sure you are in GMS 2(GMS 1.x doesn't support that function, use instance_create instead). Could you please show how are you setting up the arguments?
Hi, Im using GMS 1.4 , so what exactly i need to write there? cuz /with (instance_create(0,0,asset_get_index(_obj)))/ or / (with (instance_create(x,y,asset_get_index(_obj))) I get an error Can You help me please! Upd I already helped myself! But thanx anyway!!
I save the file and I can load it, but if I close the game and open it again and try to load it, the error appears: Data structure with index does not exist. What can I do?
So for an online game, would you use one of these files for each account and then store them on your own server? Or please do explain to me how an online saving/accounts roughly work !
supposing I created a group of different objects with their own ids, would I need to put this code in each object? Beginner here just trying to get a better understanding of how that works.
Eazy upgrade: Instead of "_string = json..."+"SaveString..."+"ds_map_destroy...". You can simply change "SaveString..." argument1 by the ds_map and in "SaveString..." add the line "_string = json_encode(ds_map)" and at the end of the script "ds_map_destroy(ds_map)". That will save you a bit of time (2 seconds every time haha) But also you will never forget to destroy the map as you need the argument or else syntax error. :) Edit: You should also; not start by a list but by a map. (map - map) instead of doing "map - list - map".
One problem I've found with this method is it changes the id of your instances (and as far as I know you are not alowed to change it back again). Guess I'll have to find everwhere I refer fo instance ID and find something elce to use?
I save the file and I can load it but if I close the game and open it and try to load the game, the error appears: Data structure with index does not exist at this line "for(var i = 0; i < ds_list_size(_list); i++)" can someone help me with that:(( trying to fix it for whole day and checking the code for many times
Hello, it's a great tutorial , but I have a little problem, when I save and then load , the player is not where it was while saving , I meant the x and y of player and all the objects that were doing some path are restored. How could I save the way they were before save ?
Thanks for this video, I was looking for a method to save stuff into files, so I can handle language versions more efficiently. Tho for some reason I thought this json_encode _decode is about to make the data unreadable and hard to modify (so it's encrypted). Is there an easy method to make this possible? And if there is a way, do you plan to make a video about it? :) I will try to put this idea in via patreon. Thanks again! I follow your tutorials for a while and I already made a minigame along the platformer tutorial series. :) Keep up the good work Shaun! :)
Hello Shaun. This is an awesome tutorial, thanks for it. I do have one question, it works wonders when the room is the same, though when moving between rooms, the objects loaded are passed to other rooms. Any one knows how to solve this? I've been trying to think a way to work around this, like a save for each room. The only problem I can think about this is for save deletion as I am trying to make a game with 3 save game slots, and making a script for code deletion seems a bit difficult for my current level of knowledge. Looking forward to hear from you guys!
Does anyone know how I could make it when you load the game, it writes all the saved variables to the objects, instead of deleting them and recreating them with the stored variables? It causes way too many dramas when I delete my control object and recreate it
hey shaun, Ive been wondering something, in my game, Ive been trying to make an hp system but it just doesn't work. here is my code. my player just dies right away. /// @desc Die if (place_meeting(x,y,oEnemy)) or (place_meeting(x,y,oEnemyBig))hp--; if (hp==0) { with (oGun) instance_destroy(); instance_change(oPDead,true); direction = point_direction(other.x,other.y,x,y); hsp = lengthdir_x(6,direction); vsp = lengthdir_y(4,direction)-2; if (sign(hsp) !=0) image_xscale = sign(hsp); }
It's because you most likely have that code in the step event which means when the player and enemy are in contact, the player loses 1 hp per frame. So it appears are if the player just dies right away. You should add knockback or inviniciblity frames when hit so that this doesn't happen. PS: I know this comment is from a year ago but maybe someone else might have the same issue in the future and this may help them.
Ok my advice is look on what exactly is happening. Also the "When I load game, the blocks disappear." is really vague, I have no idea what that could mean, like about which blocks are we talking about. My advice is to run in in debug mode, there you can set breakpoints and checks what is happening. Also you might look at Game Maker Discord server, there are chennels for solving these kind of issues.
Anybody have any idea how to LOAD different objects with different variables? I have no trouble saving different instances with different variable into a JSON but can't load more than one type of object...
You mentioned being able to add many sub levels in the JSON. I have objects with DS Lists inside their create event. I try add them to the DS Map but it only saves the reference ID. I tried using the ds_list_mark_as_map but its still only saving the reference. Anyone got a few pointers on how to expand his example to save DS Lists inside an object instead of just simple variables such as x,y, image_scale... etc? Should I simply use ds_list_write() to save the DS List? Not really readable and does not create sub levels in the JSON file. Appreciate some pointers.
If I understand your comment correctly, you're using the wrong "mark as" function! If you want to save DS Lists inside a DS Map, you need to use ds_map_mark_as_list. OR, you can use the special function ds_map_add_list, which will both add the list to the map, and mark it for you.
Hey, @Shaun Spalding! So I am working on a Space game called Vector Space (An Open-World ship game using similar controls to Asteroids, as well as graphics), and I want to make enemy ships that you can encounter. The problem is, I can't figure out how to actually make the AI without the Ship looking weird and acting weird (ex. The ship is always facing you and is moving not where the ship is looking). Do you possibly have a script or a video that would be able to help me in this sort of case? Thanks! :) -@SuperGamersGames
Alex Aulds The problem isn't the enemy's direction. The problem is being able to make an ai that move towards the player and shoots, while stay at a good distance the player and moving the enemy smoothly.
Hi I lately made a health bar and i have a problem because i don't know how do I make it so the health bar stays in the corner of the screen? Because I added a view that follows the player.
Crespo if you healthbar is not an object. Draw it in the draw GUI event. If it is an object get it’s position to equal the view width and height plus.. ... say 15. You could do this as x = camera_get_blahblahblah(camera)+15
if you make a "HTML5 multiplayer" tutorial (it seems possible, but very untouched by tutorial makers) I'll donate $100. Not sure if networking is your forte, but worth a shot. Keep the GM world alive!
Can you be more clear with the parent and child object, like the code in them because I think that's why this system isn't working for me. I'm just using a game object with no parent, and I'm accessing the global variables within, so I don't understand why this isn't working. Nvm I fixed it
Well, you could make the parent object a child of saveme, if all the children of said parent need to be saved. Otherwise you might have to create a "subparent" to distinguish between the ones you want to save, and the ones you don't. Sadly this is a limitation of GameMaker itself, with objects only being able to have a single parent, but you can definitely make it work!
I believe he middle clicked his mouse and it took him to a script that he had already created just be sure to create a blank script called SaveStringToFile then you can middle click that same spot you saw him click, yours will be blank however so just type what he has in that script.
One thing I'm wondering about is where it's saving to. I set the name as savegame.sav like in the tutorial, but I can't find that save file anywhere in the directory. Mind you, it still works perfectly for me.
Seeing "better" and "JSON" in the same sentence irks me greatly, but I suppose "better than the default GM save system" isn't the highest of bars to set :P
Sorry to bother anyone here, but using this method- is their easy way to save the contents of a rather large 2D array into a JSON file and retrieve it when loading??
you can save it as a list. Use the same code in the video, but instead of storing a map in each list, store a list in each list (so that the outer list is the rows, and the inner lists are the columns) [just remember to use ds_list_mark_as_list]
Hi Shaun, I'm making a game with an achievement room with lots of global variables that I need to save and I do not have experience when it comes to saving and loading. I've followd along your tutorial and watched the video on Juju Adams, and I was wondering how you would save and load global variables within a persistent object. Currently I have an achievement room and I have a persistent game object called obj_achievements that holds all the achievements / global variables. The way I've set up my code is that instead of an (if key pressed) to save and load, I have used the step event in my object SaveLoad to trigger to save when at the end of the game when in rm_end, and load once it has saved. Would I still destroy my object obj_achievements before loading? How should I then write to create a new object? Do I still use instance_create_layer? Should I be using something else instead of JSON? Thank you for all that you do. I really appreciate your videos.
Hey Shaun, just a quick question. I noticed in previous tutorials you used ++i inside for loops but in here you've used i++ instead. Does it make any difference besides including the first entry when using i++ as apposed to ++i? Great tutorial, once again!
There is a thing I'm not entirely sure about. At the beginning of the save script, first you create the ds_list, then you create the ds_map, and finally you add that map to the list. But at that point the map is empty, isn't it? Because you only populate the map with variables after that. I thought the order you do this would be : create the list, create the map, add variables to map and just after that you add the now populated map into the list. Or is there something I'm missing?
I thought game maker studio 2.3 was meant to be easy to use and have no coding, well that does it I am moving to construct 2 which is making things easier than both game maker studio 2.3 and Clickteam Fusion 2.5
IMPORTANT: I have made a new, updated version of this video for version 2.3.1+ using structs and arrays! ruclips.net/video/R84mR52QaMg/видео.html
I dont know anything about to save data in JSON files but Im here learning a lot, although there is another and updated tutorial. I´ll watch after this one of here.
The vertical line symbol above the backslash is called a pipe.
thank you soo much for your video, you cannot imagine how elegant is the loading/saving thanks to this code. I even extended the code so that I save game variables (in a map) and inventory list (in a list) and enemies locations and types (in a map within a list, like what you did) and finally the whole thing in one big wrapper map ^____^
You should make an online multiplayer tutorial! There aren't many Game Maker tutorials out there that cover the subject (not to mention effectively, or completely), and I feel like you could make an effective tutorial. Not only that but the Game Maker community for both GMS1 and 2 would benefit as a whole. I've been watching your tutorials for a few years now, and I would definitely want to see this!
The problem with online multiplayer is that it exceeds game maker itself. Sure you could set up clients ready for playing multiplayer but the networking solutions would need to be done outside Game Maker and would involve the use of networking knowledge as well as money to set up the infrastructure (servers) even if you plan on peer to peer you still need hole punching servers.
LAN however is easily possible and it is easily found on the internet for GMS2/GMS1.4 but it isn't online multiplayer
Getting everyone to port forward their router is a terrible idea for a commercial game, there would need to be some kind of server connect clients together using udp hole punching so people don't have to do that. (and that's just for peer to peer, not even touching on dedicated servers)
Say you release a game on Steam (also for the purpose of your argument you're not using Steam's mediation server for peer to peer, and are just using GM's network functions.) It's a 4 player rogue-like (the most common kind of game for indie devs.) They want to play multiplayer together but before buying the game have no idea what port forwarding is let alone that this game needs it to function. They press host and get a nice prompt saying ("Please port forward ports xyz on your router.") the friends who aren't hosting are fine but 1 out of 4 people will still need to go through port forwarding, which is highly unprofessional. You'd see refunds from people saying the game is broken because you're expecting players to have networking knowledge.
If you're talking about everybody (possibly thousands of players) connecting to a dedicated server made in game maker then yes, only one machine needs to have their connected router port forwarded but game maker wasn't designed to make dedicated server programs with: GM made games only run on a single core meaning there is no multi threading (something servers generally require, especially logic/ packet heavy game servers). I'm pretty sure I've read somewhere game maker networking fizzles out at sub-50 connected clients.
Lol, I don't mean to be a contrarian, if that's how it comes off.
@@AurrenTV Well I made an Online Multiplay Shoot 'em Up for my class mates and me to play. Had an in-game lobby, fluid ping and worked really good as a whole. And I only needed Hamachi for it to work! In my opinion all is right what you say except the part "The problem with online multiplayer is that it exceeds game maker itself."
I managed to do alot with GameMaker only, and simply buying a server or needing to pay for the sake of programming a game should be obvious beforehand and has nothing to do with GameMaker itself. You could say the same things for Unity or UnrealEngine in terms of Online Multiplayer therefore it makes no sense to say that GameMaker can't come up with good-enough networking solutions. I mean I even amde a voice-chat through GM Networking ^^
It's about time a good tutorial is released about saving that isn't using ini files! Ini files can get corrupted quite easily.
You posted this video just as I wanted to make saving enemy locations and your location in "Your First Platformer" possible!
did it work for you? cuz i have alot of rooms and it won't load the enemies correctly for me(they are always at full hp and at the same position)
I have been doing this list in a map with list thing in my game and didnt even know i could save it all into a JSON . Thx
Also i came here after your brief explanation you did when building your game for Ludum Dare 47.
Perfect. Was wondering when a full tutorial on this would be made.
Thanks for a tutorial on this I can follow. I do think Game Maker could make this all so much simpler they seem to have compleatly droped to ball on there usual ethos of making everthing very accessable when it comes to saving.
Thank you! I know it's a simple solution and me as a developer should know this but... you saved me!
Glad I could help!
Really useful video. exactly what I needed mate. many thanks for sharing
INCREDIBLE!! you save me :'D
I was wondering if you could make a tutorial for how to use this with the Action RPG?
Hey man I really like your tutorials and find them very useful! I could not be more thankful. Unfortunately, I would like to ask you a question about this one because I didn't get it very clear.
So the question is: if i want to add another map/list inside the root list just to have, for example, a map for keys data and a map for enemies data. When "adding" it to the root list, in the "ds_list_mark_as_map" function, should I still reference the position to be listed as "ds_list_size -1"? I mean, would it still be listed correctly?
Great tutorial! Say I have a persistent object, obj_controller that creates global variables for my game. Would I save that instance and its attributes (like how you did with x,y,sprite,etc..) and then load them into the game or should I create a new key-value pair in the ds_map and save/load that way?
Owsome 👌
Love your videos. The key you referred to is called the pipe or bar key.
I'm brand new to GML (though already a professional software dev) and saving content from my little demo GML projects has been the worst part of any of them. This seems a nice method, and JSON is a dirt simple format to work with. I'll be sure to give this a whirl when I can. :)
Though, rather than character/string data and expensive JSON processing, could a method similar to this save raw byte data to disk? It'd effectively be a memory dump stored as a map or tree.
Just two points in the video that I think need a bit of clarification:
15:00 Compatibility isn't the reason to use a buffer. Buffers are sequential data held in a temporary portion of memory. A storage device (like an SSD) is slower than RAMs, o you create a buffer for the disk to read at it's own pace, rather than sending chunks of data to the disk and waiting for said chunk to complete it's read or write operation before sending another. Buffers are more complicated to write in a high level language, but more performant since it's actually simpler to implement under the skin; there's less obfuscation with how a computer actually works.
21:08 It's just called the Vertical Bar, but in computing it's more commonly refereed to as the "Pipe" character because of it's association with the UNIX Pipeline. It's not to be confused with the broken bar ( ¦ ) which is AltGr + Grave Accent ( ` ) key on British keyboards.
My nitpicking aside, great video! I'll try to use these techniques somewhere down the line. :)
Also, hello from a fellow Northeasterner! :))
@@benanderson89 Hello from Cumbria; I was hoping someone could answer a quick question I have on this subject, but can't find an answer. I would consider myself a beginner but have been using GameMaker studio and learning about computers for 2 decades.
By using JSON to save game progress / variables and what not; Would this be the best method for my intended target which is HTML5, rendered in JavaScript? which should make this method work more natively?
One thing I have noticed with HTML5 is some events appear to be getting read from right to left making the usual windows platform logic go out the window and I have to use alternative measures to achieve similar results.
I did everything the same in the video, but now when I save and load the game, the player duplicates. In other words, one player remains as I saved, and the other reverts back to the beginning of the game. What should I do?
how dose this work with different object types (with different variables)? sould each type get its own wrapper?
Great tutorial! Definetly a life saver.
A great example. I made very similar one before, but this example has a much cleaner codes than the one I made.
so i have alot of rooms(i was following your tutorial shaun), in the save file i also put the room in which i am currently, but when i load it the enemies i killed are still there and alive(i did save their hp)
can anyone help me please
edit: instead of using a object i put the code in 2 scripts (loading and saving) don't know if that makes a big difference
i need it to be in a script so that i can call it in my menu
This video is ONLY ONE THING I NEEEEEEEEED!!!!! :)
Thank you so much, Shaun.
If anybody else cannot find where GMS2 is saving your files, drop this code in just after your save. It will pop up the directory where files are being saved in a dialogue box when you run your game. You can then remove the code from your game once you've found the file.
file_text_close(file_text_open_write("temp"))
// opens and closes a temporary text file
var r=filename_path("temp");
// creates a temporary variable with the filepath for that file
file_delete("temp"); // deletes that file
show_message (string(r));
// display a message with that file directory
file_text_close(_file); // closes the file to prevent memory leak
Don't leave this in your final game, obviously.
This works very good! just one issue, when i create the .exe file and run it this feature stops working. any idea why?
Perfect! Was hoping for this! Thank you!!!!!!!!!!!!!!!!!!!!!
How can this be expanded to include multiple different types of objects all with different variables?
@@karstenpedersen2132 nice! I think it would be interesting to use switch(_obj){ case: }
I'm getting an error when i try to load my game from the beginning saying then the data structure doesn't exists, how can i fix this
Me too! Can someone help??
I don't know if this will help, but it works for me after much pain and suffering trying to get it working in the first place.
For the loading, I had to make his load file script in the video that loads the buffer (for buffers, when it's numbers you're using use one of the buffer number ranges constants in the game maker manual, BUT if you're using text (string) then use buffer_string...this stumped me for ages since gamemaker kept saying "buffer out of range, going back to 0" and I couldn't find any guides).
Then you wanna do some stuff like...
//checks if file exists first (don't worry about name or "dat" that's just related to my game)
"if (file_exists("XGA.SAVEFILE.dat"))
{
var _map_decoded = LoadJSONFromFile("XGA.SAVEFILE.dat")
var list = ds_map_find_value(_map_decoded,"ROOT")
var size = ds_list_size(list)
//loops through whole ds list containing all the ds maps
on each list part (I think?)
for (var i = 0; i < size; i++)
{
var listvalue = ds_list_find_value(list,i)
global.variable you want to change or whatever = ds_map_find_value(listvalue, key)
Where "key" is whatever you set it to be when you saved your game using ds_maps beforehand.
.....
}
Then you destroy the list and ds map to prevent a memory leak
Hope this helps...even though it's over 6 bloody months ago 😂
Dinar 87 I’m having the same problem when I load my game: Illegal buffer index -1, obviously you wrote this a while back but I’m a little confused about how you fixed this issue?
I've seen this type of tutorial a couple of times from different YTbers. And the one thing that none of them show is saving objects that have lists/maps tied to their instances. They all say it can be done but none of them show it. Could you please give or show an example of saving/loading objects that have lists of other objects tied to them.
EXAMPLE:
In obj_player there is a variable that stores the id of another object; obj_inventory. obj_inventory is an object that stores a ds_list. In that ds_list is a bunch of instance id's of items the player is holding. How would you set this up for save/load?
Well, I would definetly *not* create inventory system based on instances in first place, that's for sure.
I would asign a number to each type of item as an enum and then I would save in a ds_list or ds_map ids of items. Because in all honesy, instance id are "tempoary".
Can you make an tutorial here on RUclips where you show us how to save our game by clicking on an object?
hey, could you make a tutorial for Google Play cloud integration and using?
Leonardo007, you know that all topics are chosen by Shaun’s patrion by a vote. It isn’t too much; $5 ish dollars a month to vote.
Try there. Not here
I have objects with different variables. Would I add a second "with statement" to include those other objects?
Nice tutorial, you really help me with this but still a have one problem, I made platform game and when I tried load game nothing happend
well first i screw up few details in code but i fix it immidiatly..
What do I do if I want to add more things to a struct, but there is already a save file that doesn't have the new variables in the json file? How do I avoid the game crashing? This would be very important for if I were to publish to steam and need to update the game.
How does one deal with saving objects with different attributes. For example a car object has speed, fuel, color. A robot has weapon strength, durability, etc. Do I need different parent SaveMe objects for each type of object, then a new with() statement for each object type? And how do I load the different types of objects in the load event?
Same problem here. I have a game in which you pick your side, the player has levels xp and upgrades, there's 9 worlds and each has 5 levels, it's teritorry based, I wont get into the details of it. Basically there's a lot of very important stuff going on
Juju Adams and Shaun both say this code is very flexible and I'm sure it is, but having to write lines for saving and loading for pretty much EVERYTHING just seems like a bad practice. Yes, you could say that I don't need everything saved, but yes, yes I do (atleast it seems like I do). Not sure how to do this properly, I've watched Jujus talk and they don't explain how to properly use it. I understand the code, they both explain it very well but I am not sure how to use it properly.
You Would Put It In Front Of The Line Of Code, Let's Say We Are Using Jumps, if No Other Object Had It You would Put:
with (Obj_Player) ds_map_add(_map,"jumps",jumps);
THX but what did you define in global.mystery
?
how would I save multiple rooms?
i wonder too
Okay i figured out how, but it’d be hard to explain over youtube comments
If you haven’t figured it out already, do you have discord? I can explain it there
Hi, One of you can explain to me how you did ? it will really help me so much !!
Romuald Henry do you have discord? I can explain it there easily
@@sylvyonosu9326 Yes I have discord, but my oral comprehension in english is very bad :/
I popped this video open because i was annoyed at how Game Maker’s native function ds_map_secure_save encrypts per device. I want to still be able to save data that can only be read by Game Maker when it loads, but not readable by a human. Essentially i want to have non-tamperable save data that i can move from machine to machine. Pardon this question but because the video is 30min long, i wanted to ask before i watched if it solves the problem i posed above. Thank you in advance.
How do I save and load a ds map? I have a minimap that relies on it, but cant figure it out...
This was great help thanks.
It hard for me, but very good tutorial of saving game! Thanks, i'll try to learn and will do it!
This is a great video, Shaun, well put together and easy to follow. However it has a major flaw, in that you simply cannot guess for all of the variables which may or may not be present in all objects at any point in the game. You see I was able to save all of the variables to the .sav file using the VARIABLE_INSTANCE_GET_NAMES function within the code. This allowed me to store any data, regardless of the object and it's variables.
Storing and saving works fine this way, I can see the data is present in the file. However your method doesn't seem to be able to pull the data out. You claim that this is more advanced than a simple text file however I still find myself having to list every possible variable at any given time, which is just not viable if you want to save the state of the game mid-battle, for example.
I'm not too sure about this... but I think in your case maybe just creating global variables to check where in they game you are? Then just save those variables as strings like in this vid. Load them upon file selection. Adjust code accordingly to them? My two cents
@Shaun Spalding Is there any way to store a ds_grid inside of a ds_list or ds_map? i've been struggling with this for a while
Don't worry... all ready solved ;)
Boys, For me the line of code SaveStringToFile just doesn't exist it comes up as a varibale any ideas?
Great tutorial! Is there any way to save a buffer inside an specific directory?
When I try to recreate all of the objects in the With statement, I get an error on the object argument within instance_create_layer. Any advice?
First make sure you are in GMS 2(GMS 1.x doesn't support that function, use instance_create instead).
Could you please show how are you setting up the arguments?
Hi, Im using GMS 1.4 , so what exactly i need to write there?
cuz
/with (instance_create(0,0,asset_get_index(_obj)))/ or / (with (instance_create(x,y,asset_get_index(_obj))) I get an error
Can You help me please!
Upd
I already helped myself!
But thanx anyway!!
@@K31774 I'm using ENIGMA and it doesn't have asset_get_index(). do you know whether this system would still work?
Where does the save file get stored?
How can edit a game for example; coin gemms etc. thanks
I save the file and I can load it, but if I close the game and open it again and try to load it, the error appears:
Data structure with index does not exist.
What can I do?
you probably destroyed the wrapper while still in loop
So for an online game, would you use one of these files for each account and then store them on your own server? Or please do explain to me how an online saving/accounts roughly work !
supposing I created a group of different objects with their own ids, would I need to put this code in each object? Beginner here just trying to get a better understanding of how that works.
Raptyrn you can put this in one parent object and use event inheritance so all child objects save
I would recommend learning .ini files first if you are a beginner
I will try both of those things, thanks!
thank you for gamemaker video
Eazy upgrade: Instead of "_string = json..."+"SaveString..."+"ds_map_destroy...". You can simply change "SaveString..." argument1 by the ds_map and in "SaveString..." add the line "_string = json_encode(ds_map)" and at the end of the script "ds_map_destroy(ds_map)". That will save you a bit of time (2 seconds every time haha) But also you will never forget to destroy the map as you need the argument or else syntax error. :)
Edit: You should also; not start by a list but by a map. (map - map) instead of doing "map - list - map".
One problem I've found with this method is it changes the id of your instances (and as far as I know you are not alowed to change it back again). Guess I'll have to find everwhere I refer fo instance ID and find something elce to use?
I save the file and I can load it
but if I close the game and open it and try to load the game, the error appears:
Data structure with index does not exist at this line "for(var i = 0; i < ds_list_size(_list); i++)"
can someone help me with that:(( trying to fix it for whole day and checking the code for many times
Hello, it's a great tutorial , but I have a little problem, when I save and then load , the player is not where it was while saving , I meant the x and y of player and all the objects that were doing some path are restored. How could I save the way they were before save ?
Did you make your player object a child of the parent saving object?
Thanks for this video, I was looking for a method to save stuff into files, so I can handle language versions more efficiently. Tho for some reason I thought this json_encode _decode is about to make the data unreadable and hard to modify (so it's encrypted). Is there an easy method to make this possible? And if there is a way, do you plan to make a video about it? :) I will try to put this idea in via patreon.
Thanks again! I follow your tutorials for a while and I already made a minigame along the platformer tutorial series. :) Keep up the good work Shaun! :)
Ok, I actually found an easy way to encrypt stuff. :) ( base64_encode _decode(); )
Hello Shaun. This is an awesome tutorial, thanks for it.
I do have one question, it works wonders when the room is the same, though when moving between rooms, the objects loaded are passed to other rooms.
Any one knows how to solve this? I've been trying to think a way to work around this, like a save for each room. The only problem I can think about this is for save deletion as I am trying to make a game with 3 save game slots, and making a script for code deletion seems a bit difficult for my current level of knowledge.
Looking forward to hear from you guys!
ds_map_add(_map, “room”, room)
Then just do an if statement where you specify a room
How do you make the script with the new 2.3 update? ;-;
is there an alternate code for ds_list_mark_as_map() ?
Does anyone know how I could make it when you load the game, it writes all the saved variables to the objects, instead of deleting them and recreating them with the stored variables? It causes way too many dramas when I delete my control object and recreate it
hey shaun, Ive been wondering something, in my game, Ive been trying to make an hp system but it just doesn't work. here is my code. my player just dies right away.
/// @desc Die
if (place_meeting(x,y,oEnemy)) or (place_meeting(x,y,oEnemyBig))hp--;
if (hp==0)
{
with (oGun) instance_destroy();
instance_change(oPDead,true);
direction = point_direction(other.x,other.y,x,y);
hsp = lengthdir_x(6,direction);
vsp = lengthdir_y(4,direction)-2;
if (sign(hsp) !=0) image_xscale = sign(hsp);
}
It's because you most likely have that code in the step event which means when the player and enemy are in contact, the player loses 1 hp per frame. So it appears are if the player just dies right away. You should add knockback or inviniciblity frames when hit so that this doesn't happen. PS: I know this comment is from a year ago but maybe someone else might have the same issue in the future and this may help them.
When I load game, the blocks disappear. Can you help me please ?
Ok my advice is look on what exactly is happening. Also the "When I load game, the blocks disappear." is really vague, I have no idea what that could mean,
like about which blocks are we talking about.
My advice is to run in in debug mode, there you can set breakpoints and checks what is happening. Also you might look at Game Maker Discord server, there are chennels for solving these kind of issues.
Anybody have any idea how to LOAD different objects with different variables? I have no trouble saving different instances with different variable into a JSON but can't load more than one type of object...
This will bypass the sandboxing?
You mentioned being able to add many sub levels in the JSON. I have objects with DS Lists inside their create event. I try add them to the DS Map but it only saves the reference ID. I tried using the ds_list_mark_as_map but its still only saving the reference. Anyone got a few pointers on how to expand his example to save DS Lists inside an object instead of just simple variables such as x,y, image_scale... etc? Should I simply use ds_list_write() to save the DS List? Not really readable and does not create sub levels in the JSON file. Appreciate some pointers.
If I understand your comment correctly, you're using the wrong "mark as" function! If you want to save DS Lists inside a DS Map, you need to use ds_map_mark_as_list.
OR, you can use the special function ds_map_add_list, which will both add the list to the map, and mark it for you.
Hey, @Shaun Spalding! So I am working on a Space game called Vector Space (An Open-World ship game using similar controls to Asteroids, as well as graphics), and I want to make enemy ships that you can encounter. The problem is, I can't figure out how to actually make the AI without the Ship looking weird and acting weird (ex. The ship is always facing you and is moving not where the ship is looking). Do you possibly have a script or a video that would be able to help me in this sort of case?
Thanks! :)
-@SuperGamersGames
image_angle = direction
Alex Aulds The problem isn't the enemy's direction. The problem is being able to make an ai that move towards the player and shoots, while stay at a good distance the player and moving the enemy smoothly.
Hi I lately made a health bar and i have a problem because i don't know how do I make it so the health bar stays in the corner of the screen? Because I added a view that follows the player.
Crespo if you healthbar is not an object. Draw it in the draw GUI event. If it is an object get it’s position to equal the view width and height plus.. ... say 15. You could do this as x = camera_get_blahblahblah(camera)+15
Thanks, this is neat.
if you make a "HTML5 multiplayer" tutorial (it seems possible, but very untouched by tutorial makers) I'll donate $100. Not sure if networking is your forte, but worth a shot. Keep the GM world alive!
check Gloomy Toad Studios - Multiplayer Fighting Game Programming
Shawn Spaulding does the thing after you pay. It’s like buying a pc off NZXT, you pay and say what you want and then they give it to you
NateStar 0 I understand, thanks. If he expressed interest I'm certain it would have panned out that way.
SaveStringToFile doesn't work for me.
I want to make a game that has multiple rooms specifically, how would i make it so it also saves what room is being used?
you can use room_get_name and then when loading it pass it through asset_get_index and load that room
Can you be more clear with the parent and child object, like the code in them because I think that's why this system isn't working for me. I'm just using a game object with no parent, and I'm accessing the global variables within, so I don't understand why this isn't working.
Nvm I fixed it
What happened if I have 2 or more room to save how can I do that....
use room_get_name to save the room name string then when your loading pass the string though asset_get_index then load the room
if we make objects that we want to save child objects of the saveme objects what do we do if the things I want to save already have a parent ?
Pea & L I think you have to copy the events into all the objects and change psaveme to the object
Well, you could make the parent object a child of saveme, if all the children of said parent need to be saved. Otherwise you might have to create a "subparent" to distinguish between the ones you want to save, and the ones you don't. Sadly this is a limitation of GameMaker itself, with objects only being able to have a single parent, but you can definitely make it work!
Got it working well on desktop. But does this work for Android on IOS?
Wow! Very complicated for me. If I need save the current values of all the variables created by me in my game is this the best way?
wtf is the SaveStringToFile function and why can't i access it
go a few seconds further in the video and you'll see the script
"SaveStringToFile()" not exist '-'
I dont understand where he went to when he highlights a bit of text and then hes in SaveStringTo File
I believe he middle clicked his mouse and it took him to a script that he had already created just be sure to create a blank script called SaveStringToFile then you can middle click that same spot you saw him click, yours will be blank however so just type what he has in that script.
One thing I'm wondering about is where it's saving to. I set the name as savegame.sav like in the tutorial, but I can't find that save file anywhere in the directory. Mind you, it still works perfectly for me.
%localappdata% folder
Will this work with scripts, like if you're trying to make an RPG in GameMaker?
GmodPlusWoW yes
Seeing "better" and "JSON" in the same sentence irks me greatly, but I suppose "better than the default GM save system" isn't the highest of bars to set :P
Sorry to bother anyone here, but using this method- is their easy way to save the contents of a rather large 2D array into a JSON file and retrieve it when loading??
you can save it as a list. Use the same code in the video, but instead of storing a map in each list, store a list in each list (so that the outer list is the rows, and the inner lists are the columns) [just remember to use ds_list_mark_as_list]
Hi Shaun, I'm making a game with an achievement room with lots of global variables that I need to save and I do not have experience when it comes to saving and loading.
I've followd along your tutorial and watched the video on Juju Adams, and I was wondering how you would save and load global variables within a persistent object. Currently I have an achievement room and I have a persistent game object called obj_achievements that holds all the achievements / global variables.
The way I've set up my code is that instead of an (if key pressed) to save and load, I have used the step event in my object SaveLoad to trigger to save when at the end of the game when in rm_end, and load once it has saved. Would I still destroy my object obj_achievements before loading? How should I then write to create a new object? Do I still use instance_create_layer? Should I be using something else instead of JSON?
Thank you for all that you do. I really appreciate your videos.
Hey Shaun, just a quick question. I noticed in previous tutorials you used ++i inside for loops but in here you've used i++ instead. Does it make any difference besides including the first entry when using i++ as apposed to ++i? Great tutorial, once again!
It shouldnt make any difference. i++ is basically the same as saying i+1 anyway
thank you =D
phuck, my brain organ.
There is a thing I'm not entirely sure about. At the beginning of the save script, first you create the ds_list, then you create the ds_map, and finally you add that map to the list. But at that point the map is empty, isn't it? Because you only populate the map with variables after that. I thought the order you do this would be : create the list, create the map, add variables to map and just after that you add the now populated map into the list. Or is there something I'm missing?
only a reference is added to the list. so even as populate it after, they reference the same map
Does this works for android projects aswell?
Probably.
I thought game maker studio 2.3 was meant to be easy to use and have no coding, well that does it I am moving to construct 2 which is making things easier than both game maker studio 2.3 and Clickteam Fusion 2.5
An IAP tutorial would be great
XenoFusion - MTG all topics are voted on patrion. Please suggest there; it is only $5 ish dollars a month
Oh wow i havnf seen 5 comments from this channel xD
"|" is called the pipe, at least in the USA.
Ох, спасибо тебе большое! Как же я долго думал) it's russian
Can you add In app purchases to a game made for steam?
(my game is an MMO btw)
Spoiler Alert "I going to Press L"