Jump to content


Photo

Saving and loading games


  • Please log in to reply
12 replies to this topic

#1 blanton

blanton

    GMC Member

  • GMC Member
  • 121 posts

Posted 17 December 2011 - 08:11 AM

How do you make it so that players can save their game and pick up where they left off the next day?

I keep trying on my own but it never works.
  • 0

#2 Lightang3l

Lightang3l

    GMC Member

  • GMC Member
  • 851 posts

Posted 17 December 2011 - 08:22 AM

You need to save the game's progress in an external file, and load it the next day.
  • -3

#3 blanton

blanton

    GMC Member

  • GMC Member
  • 121 posts

Posted 17 December 2011 - 08:46 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? :P
  • 3

#4 Mayhem Games

Mayhem Games

    Proud Kiwi

  • GMC Member
  • 955 posts
  • Version:GM:Studio

Posted 17 December 2011 - 08:51 AM

It depends on the type of game. You could use the Game Maker save system but it's crap :tongue: I would recomend using INI files.

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()

  • 0

#5 Lightang3l

Lightang3l

    GMC Member

  • GMC Member
  • 851 posts

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? :P


No disrespect, but your question should have been "How do you save game progress to external files?" don't you think? :biggrin:

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").
  • -1

#6 blanton

blanton

    GMC Member

  • GMC Member
  • 121 posts

Posted 17 December 2011 - 05:31 PM

thanks guys, sorry my question was poop, i was kinda in a rush. When i save the game using that code, will only variables stay the same? or will x and y positions get saved as well?
  • 0

#7 ƒahrenheit

ƒahrenheit

    GMC Member

  • New Member
  • 8 posts
  • Version:Unknown

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 :tongue: I would recomend using INI files.

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()


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.

  • 0

#8 kollinsoftware

kollinsoftware

    GMC Member

  • GMC Member
  • 8 posts
  • Version:GM:Studio

Posted 18 December 2011 - 11:14 PM

My favorite way to save game data is through the windows registry. It is relatively simple:

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
  • 0

#9 sageamagoo

sageamagoo

    GMC Member

  • New Member
  • 3 posts

Posted 30 December 2011 - 09:23 PM

Here's a really good way to save games.

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!
  • 0

#10 sageamagoo

sageamagoo

    GMC Member

  • New Member
  • 3 posts

Posted 30 December 2011 - 09:27 PM

And yes, EVERYTHING gets saved. Maybe too much for your liking, but you can work around that if it's a problem.
  • 0

#11 gardian20

gardian20

    GMC Member

  • GMC Member
  • 99 posts
  • Version:GM:Studio

Posted 03 March 2012 - 10:33 PM

Ok.........just do
game_save(<name>)
//and
game_load(<samename as made in the last stement>)

  • 0

#12 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2295 posts
  • Version:GM7

Posted 03 March 2012 - 11:05 PM

Edit: Ah shoot, didn't realised it got necro bumped ;) Wanna lock it nocturne?

Edited by greep, 03 March 2012 - 11:09 PM.

  • 0

#13 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16793 posts
  • Version:GM:Studio

Posted 03 March 2012 - 11:06 PM

Guys, calm down... last post was in december. I think we can assume that the OP is no longer interested or has resolved his problems!
  • -1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users