Simon Donkers's Game Maker site siteSimon Donkers's Game Maker site
Version: GM 5+6 Views: 40378 Script, Game Maker 5 and 6 compatible
Filesize: 1189 byte Creative Commons License

Save and load script

1/52/53/54/55/5 (72 votes)

A script which let the user enter a filename to save or to load a game with a standard windows message screen. An editable message screen can be achieved by using the open example on the examples page

 Save and load script
//////////////// Save and load script ////////////////////
// Copyright Simon Donkers 27-1-2005
// -
// argument0 = 0 for saving, 1 for loading
// argument1 = file extension. For example .sav
// Do not add a '*' sign for the extension
// standard directory is the directory the game stands in
var Savegame,Loadgame;
if argument0 = 0 then
  SaveGame = get_save_filename('SaveGame(*' + argument1 + ')|*' + argument1 + '', '');
  if SaveGame != '' then 
    if string_copy(SaveGame, string_length(SaveGame) - 3, 4) != argument1 then 
      SaveGame = SaveGame + argument1;
  LoadGame = get_open_filename('Save games|*' + argument1 + '', '');
  if (LoadGame != '') then 
    if file_exists(LoadGame) then 

Tip: Have a look at the tutorial How to execute a script

User comments

 N/A posted at 2005-09-05 19:14:23Quote
good job
 N/A posted at 2005-09-30 19:19:04Quote
Don't work with gamemaker 6.1!
 N/A posted at 2006-05-03 19:14:36Quote
Of course that yes!
 schalk bower posted at 2006-05-06 05:44:42Quote
can u plz post an gm6 example any1?
 schalk bower posted at 2006-05-06 09:38:30Quote
wow thanks man this is the best script eva :) . this is going to make my game so better u are the best gamemaker scripter ever!!!!!!!
 Stijn posted at 2006-06-07 17:56:18Quote
Damn it wouldn\'t work; Wrong number of arguments :s
 GameMakinRyan posted at 2006-07-27 18:13:13Quote
No guys, if you want it to work, yuo have to set it up like this. Lets say you're running this script from a piece of code, it would look like this


*The save_load can be subsituted with the name of your script.
 samushi posted at 2006-10-30 10:58:21Quote
could u help me, cause I tried it and it didn't work! I put an action "execute a script", selected the saving one, and pressed ok. what aruments should i put there? what does mean "argument0 = 0 for saving, 1 for loading"?
 Simon Donkers posted at 2006-10-30 15:03:52Quote
Hello samushi.

To save a game with .sav extension you can use (if the script is named save_load)
To load the game you use:

See the tutorial 'How to execute a script' for more information. Enjoy.
 samushi posted at 2006-11-02 10:51:02Quote
WOW! thankz, man! this script has done so much! now my game is cooler and i understand GML better!
 Rob posted at 2006-12-13 19:16:03Quote
it doesn't work
 Donkey posted at 2007-01-02 13:59:04Quote
In wich event i have to put this?
I did release enter. but nothing happend... can you make a example please?
thank you.:)
 Thanks a bunch!!!!!!!!!!!!!!!!!!!! posted at 2007-03-29 03:08:40Quote
This is AWESOME!!!!!!!!!!!!!!!!!!!

 It works posted at 2007-05-12 18:41:42Quote
Like the name says man!
 Dalortins posted at 2007-07-07 20:32:47Quote
I used your script and made it as an action using Library Maker. But the script works for me and i like it.
 Trident posted at 2007-08-08 04:09:20Quote
 jared posted at 2007-09-21 18:23:39Quote
I just need some simple scripts for an RPG game that im doing for school can anyone help me???
 Dazzque posted at 2008-03-04 16:47:18Quote
Hey! I am the programmer of Doom Nightmare-Games and i just want to ask anyone about scripts. Ex. I want to make a WWW-button to my website in the game but it just wont work! I tried this:
It just wont work! Can anyone guide me to a website for script-programming-amatours! Please!
 anon posted at 2008-03-22 04:26:37Quote
I keep getting an error:

In script script_:
Error in code at line 15:
SaveGame = get_save_filename('SaveGame(*' + argument1 + ')|*' + argument1 + '', '');

at position 48: Wrong type of arguments to +.

How can I resolve this?
 stefan posted at 2008-03-22 16:37:49Quote
i keep getting an error: to

the same as above, this messes.

Error in code at line 15:
SaveGame = get_save_filename('SaveGame(*' + argument1 + ')|*' + argument1 + '', '');

at position 48: Wrong type of arguments to +.

the script won't work at all. can you please a script that work.

 tyga101 posted at 2008-03-30 07:39:33Quote
Can you please help me make a platform game where the players sprite moves. The way I make it, when you have to move, it creates it again, right next to the privious one, thus, restarting the sprite and going to frame 0.HELP ME if you don't me.
 Viski posted at 2008-03-31 15:43:11Quote
Works fine for me. Thanks a lot! =)
 NN KH Maker posted at 2008-05-21 19:54:29Quote
yo :d nice script but dont know how to use it
 Mr.Noname posted at 2008-05-26 15:19:06Quote
i've seen many people have this problem and make a script called'image_single2'
in the script put:
and lets say you want frame2 and speeds of 3
then have in code:
 zergber posted at 2008-08-07 07:40:29Quote
I don't know much about GML but it would be a good idea to put
if SaveGame != ''
because if you push cancel it'll create an error.

Thanks for script :D
 chris posted at 2008-08-27 12:13:01Quote
i tried this script and although it works, once it finishes is comes up with
at position 48: Wrong type of arguments to +. if i press ignore it go's away but it is quite anoying and anyone playing it will think it stuffed up
 masterno posted at 2008-10-21 22:30:38Quote
COMPILATION ERROR in Script: save_load
Error in code at line 19:
if (LoadGame != '') then

at position 4: Unexpected symbol in expression.

damn how?????? i try to fix this problem how??? plz someone help me finish it!!!
 woot posted at 2008-11-09 01:58:03Quote
One word...A-MAZ-ING.
 dyla posted at 2009-01-14 03:21:46Quote
you are awsome, this worked extremely well!!! thank you so much
 SpeedCoreFreaK posted at 2009-03-09 21:22:44Quote
Thank u so much I needed this !
 jora posted at 2009-04-11 11:28:03Quote
first where must i put the script in? (event)
second how can i let it save and load !!?
third how does it work !!!
 Sonica posted at 2009-06-28 11:20:58Quote
WOW That is the only one that ever worked for me, you are a hero.
 Taltius posted at 2009-09-17 22:29:11Quote
Nice job with the script, good job making it easy to change.
 sean posted at 2009-10-03 03:22:24Quote
action number 1
of Mouse Event for Right Button
for object object0:

Error in expression:.sav
position 1: Unexpected symbol in expression.

how do i fix this
 Sonica posted at 2009-10-17 16:29:09Quote
instead of:
 food3126 posted at 2009-11-29 16:51:45Quote
zergber, thank you so much, i kept getting that error and it was driving me insane!!!!!!!!
 Zsalugater posted at 2009-12-13 20:54:31Quote
Really nice one, thanks a lot for it!
 Me posted at 2009-12-23 23:12:06Quote
Thanx! This helped me a lot.
 Bobulus Squishead posted at 2010-01-29 17:31:27Quote
This is amazing!
Thanks so much!
It's really helped!
 Danny posted at 2010-03-21 20:08:23Quote
How do I make it so if the player presses 'New Game', it overwrites the old save file? And also, how do I make it so if the save file doesn't exist, it starts at the first room in the game?
 michael posted at 2010-03-26 23:09:20Quote
i have no idea how to use the script. i really need some help plz
 GabMesIRT posted at 2010-05-30 21:27:03Quote
Is There a way to save and choose where you want to save it and to change your save name and that when you load it you can find it in a directory ?
 Anonymous posted at 2010-07-13 11:04:39Quote
The file name says SaveGame(.sav) when i saved the game.
When i load, the file name says SaveGame
. I can't load the file just because of that.
 Lestat posted at 2010-08-13 12:32:02Quote
You're awesome!! If only I was that good at GML.
 A guy who wants to make a decent game for the love of making games posted at 2010-08-23 06:12:31Quote
I have no idea what any of this means, some people get it, and love you because it works, some people sort of get it, but mess, up, some people, such as myself, have no idea where to start exactly, so please answer our calls and give us CLEAR STEP BY STEP INSTRUCTIONS!!!PLZ it will make our lives oh so better...
 Simon Donkers posted at 2010-08-23 09:52:18Quote
There is a tutorial how to execute a script, linked from right above this list of comments.
That explains how to use this script.

Note that this site is aimed at intermediate Game Maker users. There is also no reason to spam in this comment form if you don't get a reply within half a day.
 scott posted at 2010-09-28 05:38:42Quote
when you press cancel you get an error:

action number 1
of Key Press Event for <Space> Key
for object Obj_Controler:

Failed to save game to file
 Ilumina posted at 2010-10-02 05:59:49Quote
a game
 Nhlanhla Charles Makhaye posted at 2010-11-17 10:50:59Quote
i keep getting a same error as stefan

the same as above, this messes.

Error in code at line 15:
SaveGame = get_save_filename('SaveGame(*' + argument1 + ')|*' + argument1 + '', '');

at position 48: Wrong type of arguments to +.