Jump to content


Photo

Game crashing when loading a save file?


  • Please log in to reply
5 replies to this topic

#1 Cloud Architect

Cloud Architect

    GMC Member

  • New Member
  • 462 posts

Posted 06 February 2012 - 12:06 AM

Sup dudes.

I've got a really bizarre problem to do with the inbuilt 'game_save' and 'game_load' functions when I use them in my game. I can't pinpoint it down to what piece of code isn't working so I can't post anything of that nature here for now unless I find out suddenly :/

I created a main menu which has a 'new game' and 'continue game' option. I wrote the code so that I could save by pressing space during the main game so I could test it, when I exit from the main game to the main menu and press continue it loads perfectly. I can also save it as a file so I can select different ones and they all work.

But when I exit my game, and re-open it, to test if it'll open after the game has been closed, when I go to continue on my main menu and open any file, it crashes the game, even though it worked when I saved and loaded while the game was running. What in the name of...

I tried making a separate room for loading games in to see if it was to do with the controls in the step event of my menu object but they weren't bugged out at all.

Does anyone have any ideas what might be happening? I really am completely lost on this one.

Cheers x

Edited by Cloud Architect, 07 February 2012 - 05:54 PM.

  • 0

#2 FoxInABox

FoxInABox

    GMC Member

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

Posted 06 February 2012 - 12:26 AM

I think it could have something to do with what is saved and what is not, for example .. if you have a ds_list, if you load a game you just saved then it will still have the list there, but if you close the game then the list is removed from memory, and when you load it then it isn't there when some code migth need it..

solution for that is to change a variable just before saving ..

recover=true;
save_game()
recover=false;

when you load then it will still be set to true, then you can have a event trigger and recreate the lost ds_list and then set recover to false again ..

Edited by FoxInABox, 06 February 2012 - 12:27 AM.

  • 0

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 06 February 2012 - 12:33 AM

Also if you are using dlls or plugins... you may have troubles when loading a game in subsequent games runs.
  • 0

#4 Cloud Architect

Cloud Architect

    GMC Member

  • New Member
  • 462 posts

Posted 06 February 2012 - 12:48 AM

I think it could have something to do with what is saved and what is not, for example .. if you have a ds_list, if you load a game you just saved then it will still have the list there, but if you close the game then the list is removed from memory, and when you load it then it isn't there when some code migth need it..

solution for that is to change a variable just before saving ..

recover=true;
save_game()
recover=false;

when you load then it will still be set to true, then you can have a event trigger and recreate the lost ds_list and then set recover to false again ..


I think I understand what you mean, like bits of the data that should be around aren't there because exiting the game removes the cache stuff from memory so when you load it it's gone?
I don't see why that would happen when I save everything as an actual save file though with a file extension that I can actually pick to load, I thought gamemaker would have that kind of thing covered really at a fundamental design level.

Also if you are using dlls or plugins... you may have troubles when loading a game in subsequent games runs.


I just tried removing all of the extensions I was using to see if they were messing everything up. It didn't work. I'm not using any DLL's tho.

--
Want me to post my game source? Haha, it might be a bit easier seeing as this problem seems like it's a bit complicated. Can't see any other ways around it really. Cheers for the fast replies by the way, really helpful stuff x

Super edit: I've noticed that loading up a saved game makes the game insanely corrupt, like rain particles continue where they shouldn't, etc (even though they work before saving). Is there a better way to do this saving stuff rather than using the built in save features? Seems like either yoyogames have a lot of work to do on their save feature, or I suck aha. Need to get some sleep as well so I'll be back on soon x

Edited by Cloud Architect, 06 February 2012 - 12:57 AM.

  • 0

#5 FoxInABox

FoxInABox

    GMC Member

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

Posted 06 February 2012 - 01:18 AM

f=file_text_open_write('mysave.sav') // prepare a file to write to, store it index in 'f' that we will use in the other file_ functions

file_text_write_real(f,health)
file_text_writeln(f) // linechange (it doesn't do it by itself)

file_text_write_real(f,room)
file_text_writeln(f)

file_text_close(f) // allways remember to close the file afterwards

when loading we do it the other way.. kinda:
f=file_text_open_read('mysave.sav')

health = file_text_read_real(f)
file_text_readln(f) // next line

temp = file_text_read_real(f) // note that I store the room in that variable so I don't trigger the roomchange yet
file_text_readln(f) // next line

file_text_close(f) // there we go.. file closed and we can change room now

room = temp;

did that make sence.. basicly you get alot more controll of what is saved, and the savefile will be so mutch smaller
  • 0

#6 Cloud Architect

Cloud Architect

    GMC Member

  • New Member
  • 462 posts

Posted 07 February 2012 - 05:43 PM

f=file_text_open_write('mysave.sav') // prepare a file to write to, store it index in 'f' that we will use in the other file_ functions

file_text_write_real(f,health)
file_text_writeln(f) // linechange (it doesn't do it by itself)

file_text_write_real(f,room)
file_text_writeln(f)

file_text_close(f) // allways remember to close the file afterwards

when loading we do it the other way.. kinda:
f=file_text_open_read('mysave.sav')

health = file_text_read_real(f)
file_text_readln(f) // next line

temp = file_text_read_real(f) // note that I store the room in that variable so I don't trigger the roomchange yet
file_text_readln(f) // next line

file_text_close(f) // there we go.. file closed and we can change room now

room = temp;

did that make sence.. basicly you get alot more controll of what is saved, and the savefile will be so mutch smaller


Cheers man! I discovered the particle system was getting messed up whenever I saved the game and busted my brain for a while trying to figure out why. I'm using a heavily modified version of what you put underneath here. And best of all, the particle system doesn't get screwed over saving in this way. I like the degree of control I have as well. It's much better. Cheers dude!

The only problem with this method is the fact that it's very insecure and easy to cheat with by modifying the text file. Is there a more secure way of doing this?

Edited by Cloud Architect, 07 February 2012 - 05:55 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users