You are on page 1of 6

25/3/2014 Is There A Simple Save/Load Function For Ios Yet?

- iOS - Game Maker Community


http://gmc.yoyogames.com/index.php?showtopic=573249 1/6
Game Maker Communit y GameMaker Technical Suppor t - GameMaker : St udio iOS
Is There A Simple Save/Load Function For Ios Yet?
Started by theREVOsty le, Mar 04 201 3 05:1 9 AM
theREVOstyle
Hey there,
I've spent the last year working on a title for the ios platform,
A simple, yet huge maze game, containing many levels and variables.
After a year in the making I have hit a brick wall, as I have just noticed that unless I find a way for the user to save
his/her progress, they are continuously restarting the game.
I have briefly looked into .ini files, but have absolutely no clue in that area and am pretty much relying on YoYo to
simplify this imperative option for us less experienced users.
Until then my masterpiece is at a stand still
Does such thing exist at present?
Thanks,
BJ
Post ed 04 Mar ch 2 01 3 - 05 :1 9 AM
Loaf
You could write and read to text files. You could do it as simply as writing a 1 to a save file each time a level is
unlocked, then reading how many 1's there are and unlocking the amount of levels accordingly.
save = file_text_open_write("save.sav");
file_text_write_string(save,"1");
file_text_close(save);
You'd want to check if it exists and append it probably, but that'll write a first save.
Then to read I'm guessing something like
loadfile=file_text_open_read("save.sav");
loaddata=file_text_read_string(loadfile);
global.level_amount = string_count("1", loaddata);
file_text_close(loadfile);
Not 100% sure on that code, its a guess.
The save / load system was an issue for me, and I was dreading it. But during the later stages of my game dev, I
suddenly figured out how to do it and made a save / load system in 48 hours. In my game, its a nightmare, because
one feature lets the user place objects and they can change states (different sprites, different variables, etc).
This is how one of my custom save files looks:
Post ed 04 Mar ch 2 01 3 - 05 :2 8 AM
25/3/2014 Is There A Simple Save/Load Function For Ios Yet? - iOS - Game Maker Community
http://gmc.yoyogames.com/index.php?showtopic=573249 2/6
Quote
6
0.7 7
0
0
0
0
0
50
0
26
3
27 1 9
-7 6
-49
1 23
John
Example
1 0
2
6
2000
Example
81 |1 884|468|0|1 20|0|9991
1 39|1 656|468|0|1 92|0|9992
97 |1 080|468|0|1 44|0|9993
99|924|468|0|1 47 |0|9994
95|1 020|468|0|1 41 |0|50002
45|1 584|468|0|66|0|9996
9|1 500|468|0|9|0|9997
27 |1 1 40|468|0|38|0|9997
287 |1 296|468|0|27 2|0|9999
People will usually warn you away from the GameMaker save feature, because if you update your game it'll almost
certainly break it.
Edited by Loaf, 04 March 2013 - 05:35 AM.
theREVOstyle
ahh that will definitely be alot easier!
Regardless, Im going to have to have to learn a thing or two, as I have pretty much created this entire app using
GameMakers drag n' drop interface. No coding.
So I am still a little unsure how to include this code in an event and have it interact with other 'drag n' drop' variables
that I include in the event.
But this looks a heck of alot easier to learn rather than investigating into '.ini' files.
Yeah that makes sense, I didn't think of that (Updates resetting progress).
Just out of curiousity, do you know if GameMaker has released this simple SAVE/LOAD function?
Thanks man
Post ed 04 Mar ch 2 01 3 - 1 2 :5 8 PM
@Alex@
GameMaker-Studio no longer supports the "simple" save and load functions (game_save(filename) &
game_load(filename)) all this functionality can be easily replicated for a specific game using ini or text files. The
manual is a great resource for learning about these. But you should also look around the tutorials section.
Post ed 04 Mar ch 2 01 3 - 09:40 PM
Loaf
'theREVOstyle', on 04 Mar 2013 - 09:58 AM, said:
Post ed 05 Mar ch 2 01 3 - 02 :1 6 AM
25/3/2014 Is There A Simple Save/Load Function For Ios Yet? - iOS - Game Maker Community
http://gmc.yoyogames.com/index.php?showtopic=573249 3/6
Regardless, Im going to hav e to hav e to learn a thing or two, as I hav e pretty much created this entire app using
GameMakers drag n' drop interface. No coding.
So I am still a little unsure how to include this code in an ev ent and hav e it interact with other 'drag n' drop' v ariables
that I include in the ev ent.
But this looks a heck of alot easier to learn rather than inv estigating into '.ini' files.
Alright, so the snippet I've given you can be used with the GML code event. Lets say you just want it to automatically
go to the latest level when the user presses a continue button, you could use the load code above in it. Lets say you
have 5 rooms, a splash screen, a main menu, and 3 levels.
You get a list of 0 to however many rooms you have, so level 3 has the id of 4. If the save file has three 1's in it, which
was my example of counting levels, then the string_count function in my previous post should give us a value of 3
which would be stored in global.level_amount in the example. Global variables can be used anywhere by any object.
So we could then add this to the button:
room_goto(global.level_amount + 1);
room_goto lets us move to a new room. Since global.level_amount is equal to 3, we just need to add 1 more to the
value to give it ID 4, which matches the level3 room. This is how the load system could work.
After a user enters a new level, all you need to add is this to the code that lets the player progress:
save = file_text_open_append("save.sav");
file_text_write_string(save,"1");
file_text_close(save);
I think that should work, it should just add a 1 on the end of the save. Using append stops it from erasing everything
else in the file.
But yeah, go play around with file writing, maybe look up some downloadable examples or spend a while testing. It'll
be easy to you once you get the hang of it. Its a pretty good thing to learn early on if you are easing into GML as well.
Edited by Loaf, 05 March 2013 - 02:18 AM.
theREVOstyle
Wow! @Loaf , Thanks heaps!
That's almost exactly what i needed to see!
Post ed 05 Mar ch 2 01 3 - 05 :06 AM
25/3/2014 Is There A Simple Save/Load Function For Ios Yet? - iOS - Game Maker Community
http://gmc.yoyogames.com/index.php?showtopic=573249 4/6
And i'm assuming the same principal will apply to score? (Just made up of 1's)
Loaf
Well for the score you could just write it as a variable to the text file. Are you using the default score system? The
GameMaker guide says it saves this as a global variable "score". You have two options really-- the easiest but least
efficient option is to make another file, like score.sav, and just write it as text:
file_text_write_real("score.sav",score);
You could then have a separate object that loads. However, really you want a single file. But this would mean you
couldn't use the code in the last post, because it just appends the save with 1's. If you have a score system, you'd want
to be writing two lines. So perhaps instead, we can be even more clever.
Really, you can interpret the information anyway you want. Instead of writing a bunch of 1's, you could just write the
room ID, come to think of it.
So each room change could be something like this:
//Save the game every time a person progresses
save = file_text_open_write("save.sav"); //Erases the previous save
file_text_write_real(save,score); //Writes the variable 'score' which is a default variable if you use D&D score
functions
file_text_writeln(save); //Next line
file_text_write_real(save,room); //GameMaker uses the variable 'room' for the current room ID it seems
file_text_close(save);
and on load it could be as easy as this
loadfile=file_text_open_read("save.sav"); //Open the save
score=file_text_read_real(loadfile); //Turn the score variable into the first line
file_text_readln(loadfile); //Next line
leveldata=file_text_read_real(loadfile); //Save this number for room change
file_text_close(loadfile); //Close file
room_goto(leveldata); //Change to the room
This should work perfectly if you copy it in-- actually, be sure to test and read up on it, I just assume from memory
and look up a few things in the manual. Its untested.
Post ed 05 Mar ch 2 01 3 - 08:1 0 AM
theREVOstyle
Yeah I'm using both the default Score and Lives variables.
These are all of the global variables being used in my game;
global.gasmeter (0-3 , Eats chocolate to build up his 'Fart meter' - made up of 3 stages)
global.level (standard levels)
global.rare1 (0-1 , both of these are required to open a certain door)
global.rare2 (0-1 , both of these are required to open a certain door)
global.gotpotion (0-1 , object of the game - collects, then doubles moving speed)
global.clockedgame (0-1 , if game is finished - changes menu interface)
global.survivallevel (survival mode - highscore)
Score (default)
Lives (default)
I think ill start off incorporating this txt save system into the global score first, to get an idea, export it, see how it
goes.
Then ill gradually branch out to all of the relevant global variables until they're all being saved this way
Post ed 06 Mar ch 2 01 3 - 05 :03 AM
25/3/2014 Is There A Simple Save/Load Function For Ios Yet? - iOS - Game Maker Community
http://gmc.yoyogames.com/index.php?showtopic=573249 5/6
I'm in no hurry. Deadline isnt until near the end of the year
Manuel777
Hasnt anyone tried buffers to store data yet? they are pretty handy, and not only they reduce filsize a lot, but they
are incredibly harder to hack. Here is a very simple save/load example:
Save data:
buffer = buffer_create(512, buffer_grow, 1);
buffer_seek(buffer, buffer_seek_start, 0);
buffer_write(buffer, buffer_u32, coins);
buffer_write(buffer, buffer_u8, level);
buffer_write(buffer, buffer_string, username);
// And so on..
buffer_save(buffer, "save.sav");
buffer_delete(buffer);
That code saves the variables 'coins', 'level' and 'username' to save.sav
Now, to load:
buffer = buffer_load("save.sav");
coins = buffer_read(buffer, buffer_u32);
level= buffer_read(buffer, buffer_u8);
username= buffer_read(buffer, buffer_string);
buffer_delete(buffer);

Post ed 06 Mar ch 2 01 3 - 06:2 5 PM
theREVOstyle
wow man!
That's even easier!!
I'm just unsure about one thing in your example;
The buffers differ between variables..
buffer_u32, coin
&
buffer_u8, levels
What's the difference between the two?
Thanks for your help man
Post ed 1 1 Mar ch 2 01 3 - 01 :46 AM
Manuel777
'theREVOstyle', on 10 Mar 2013 - 10:46 PM, said:
wow man!
That's ev en easier!!
I'm just unsure about one thing in y our example;
The buffers differ between v ariables..
buffer_u32, coin
&
buffer_u8, lev els
What's the difference between the two?
Post ed 1 1 Mar ch 2 01 3 - 02 :2 1 AM
25/3/2014 Is There A Simple Save/Load Function For Ios Yet? - iOS - Game Maker Community
http://gmc.yoyogames.com/index.php?showtopic=573249 6/6
Back to iOS
Game Maker Communit y GameMaker Technical Suppor t - GameMaker : St udio iOS
Thanks for y our help man />
Well that is on the help file, they are different sizes of variables, and the bigger the data type the more space it will
use, but the range of numbers it can store is also bigger; Say buffer_u8 can store values from 0 to 255 only,
buffer_s8 can store values from -127 to 128, buffer_u32 can store values from 0 to 4,294,967,295. (s means
'signed', u means 'unsigned')
It is all specfied in the help file, under buffer_read() and buffer_write()
theREVOstyle
Ahh.. and that explains it!
Thanks man!
Post ed 1 2 Mar ch 2 01 3 - 04:07 AM
Mr. RPG
'Manuel777', on 06 Mar 2013 - 3:25 PM, said:
Hasnt any one tried buffers to store data y et? they are pretty handy , and not only they reduce filsize a lot, but they are
incredibly harder to hack. Here is a very simple sav e/load example:
Sav e data:
buffer = buffer_create(512, buffer_grow, 1);
buffer_seek(buffer, buffer_seek_start, 0);
buffer_write(buffer, buffer_u32, coins);
buffer_write(buffer, buffer_u8, level);
buffer_write(buffer, buffer_string, username);
// And so on..
buffer_save(buffer, "save.sav");
buffer_delete(buffer);
That code sav es the v ariables 'coins', 'lev el' and 'username' to sav e.sav
Now, to load:
buffer = buffer_load("save.sav");
coins = buffer_read(buffer, buffer_u32);
level= buffer_read(buffer, buffer_u8);
username= buffer_read(buffer, buffer_string);
buffer_delete(buffer);
Is the concept the same with saving with .inis? So there basically isn't any reason not to save with buffers?
Post ed 1 2 Mar ch 2 01 3 - 04:5 8 AM

You might also like