Saving and loading games
#1
Posted 17 December 2011 - 08:11 AM
I keep trying on my own but it never works.
#2
Posted 17 December 2011 - 08:22 AM
#3
Posted 17 December 2011 - 08:46 AM
#4
Posted 17 December 2011 - 08:51 AM
Save example
ini_open("SaveGame.sav")
ini_write_string("General","Username","Mayhem Games")
ini_write_real("Player","Level",100)
ini_close()Load example
ini_open("SaveGame.sav")
Username = ini_read_string("General","Username","")
Level = ini_read_real("General","Username",0)
ini_close()
#5
Posted 17 December 2011 - 08:56 AM
okay nice way of putting it. The question for those of you who take everything literally is how do i go about saving the games progress in an external file?
No disrespect, but your question should have been "How do you save game progress to external files?" don't you think?
I use an ini file to save and load... and it's basically like Mayhem Games said. I would also suggest checking if the file exists before preforming ini_open("SaveGame.sav").
#6
Posted 17 December 2011 - 05:31 PM
#7
Posted 18 December 2011 - 08:30 PM
It depends on the type of game. You could use the Game Maker save system but it's crap
I would recomend using INI files.
Save exampleini_open("SaveGame.sav") ini_write_string("General","Username","Mayhem Games") ini_write_real("Player","Level",100) ini_close()
Load exampleini_open("SaveGame.sav") Username = ini_read_string("General","Username","") Level = ini_read_real("General","Username",0) ini_close()
I'm going to revise my previously near posted question and simply ask for an explanation on how the read syntax goes about pulling the string informations from the .ini file.
Why in the write example does the level get set to a value of 100. then in the read query is it 0?
Ill also ask, how would one go about these few things.
Saving and Reading a character save file from a server database?
Possibly Encrypting the file if the above is not possible.
I'm designing an online multiplayer game, and i am familiar with SQL, So I'd like to build my file system around that principle. So that the save files cannot be tampered with [unless they were to hack into the server]
all I need to know is if the same file example can have a directory pointed at the servers DB for save files. and if so how or a small example of how
Edited by ahrenheit, 18 December 2011 - 08:39 PM.
#8
Posted 18 December 2011 - 11:14 PM
To save a string (insecure, easy to change, which is bad if it is a level or something):
registry_write_string("variable_name","data to save")To save a number (secure, because it converts it into binary):
registry_write_real("variable_name",1)To read a string:
variable=registry_read_string("variable_name")To read a number:
variable=registry_read_real("variable_name")Make sure you keep the variable name in quotes!
-Kollin
My site is: kollinsoft.tk
#9
Posted 30 December 2011 - 09:23 PM
I made a tutorial, that's extremely idiot-proof. I probably went too in-depth, but here it is:
Okay, here we go.
This is the code you need to put in a script to save/load your game.
{
var Savegame,Loadgame;
if argument0 = 0 then
{
SaveGame = get_save_filename('SaveGame(*' + argument1 + ')|*' + argument1 + '', '');
if SaveGame != ''
{
if string_copy(SaveGame, string_length(SaveGame) - 3, 4) != argument1 then
SaveGame = SaveGame + argument1;
if SaveGame = argument1 {exit} else {game_save(SaveGame)}
}
else
{
exit
}
}
else
{
LoadGame = get_open_filename('Save games|*' + argument1 + '', '');
if (LoadGame != '') then
if file_exists(LoadGame) then
game_load(LoadGame);
}
}
First, you need to have advanced mode turned on. If you do, you should be able to see a folder called "Scripts" on the main Game Maker screen.
If you don't, turn it on by going under file, and clicking "Advanced Mode".
Now that you have that turned on, right-click the folder "Scripts" and click Create Script. Now a window pops up saying "Script Properties" or the like. Now copy the code, listed above, and paste it into this window.
To make sure you don't have any errors, click the button with
10
01
written on it. (If you're using Game Maker 8, don't worry about this, it's already turned on and will alert you of errors at the bottom of the screen)
If you copy/pasted the script wrong, it will tell you at the bottom of the screen. Redo the copy-and-pasting. If it's right, go ahead and click the green checkmark.
Now, double-click the object you want to use for saving. This will probably be the player object, or some save button object. Click "Add Event" at the bottom of the screen, and select the "Key Press" event, then the button you wish to use for saving. (It's important not to choose a Keyboard event, as this may cause a loop).
Now, you'll want to implement the script. On the right side of the screen, select the "control" tab. Then drag the picture of the paper with a green arrow (Execute Script) into the screen labeled "Actions". A screen pops up with a bunch of arguments listed. Since you're saving the game, "argument0" needs to be a 0. Argument1 should be this: '.sav'
It's important to keep the apostrophes in.
Click the OK button, and you're done. Test this out, and make sure it works by playing the game.
Once you've done that, you need to make it so you can load the game aswell. Follow the previous steps to make a different key press event, and drag over "execute script". Now, because you're loading the game, you need to change "argument0" to a 1. Make argument1 '.sav' much like you did the last time, and you're good to go.
Good luck, and happy gaming!
#10
Posted 30 December 2011 - 09:27 PM
#11
Posted 03 March 2012 - 10:33 PM
game_save(<name>) //and game_load(<samename as made in the last stement>)
#12
Posted 03 March 2012 - 11:05 PM
Edited by greep, 03 March 2012 - 11:09 PM.
#13
Posted 03 March 2012 - 11:06 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











