Author Topic: Saving Game  (Read 5556 times)

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Saving Game
« on: 2008-03-21, 04:13:24 PM »
I'm trying to figure out how to get save games working properly, but I can't get it to work.
The save and load functions are activated when clicking on a specific sprite; here are the rules I am using:
Code: [Select]
Saving:
 If Clicked On
   If On the Title Screen{
      Switch to 'First Level' map
      Set 'CurrentSave' Counter to 1
      Save Game to 'CurrentSave' Slot, InMemory = False (because that should save it to a file?)
   }
   Else (not on the starting Map)
      Save Game to 'CurrentSave' Slot, InMemory = False
End

Code: [Select]
Loading from Title Screen:
If Clicked On
  Set 'CurrentSave' Counter to 1
  LoadGame 'CurrentSave' Slot, InMemory = False
 
Code: [Select]
'Quickload' In Game:
If Clicked On
  LoadGame 'CurrentSave' Slot, InMemory = False

Using the 'Quickload' works fine inside the game. However, if I turn off the game, start it up and try to load a saved game, it crashes with a bunch of errors.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Saving Game
« Reply #1 on: 2008-03-22, 12:42:23 PM »
What are the errors?

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Saving Game
« Reply #2 on: 2008-03-22, 01:10:54 PM »
Code: [Select]
A Fatal error occured initializing or running the game:
System.NullReferenceException: Object reference not set to an instance of an object.
  at Sprites.Spikes.get_Item(Int32 state)
  at SpriteBase.GetBounds()
  at LayerBase.IsSpriteVisible(SpriteBase sprite)
  at LayerBase.InjectSprites()
  at StartForest_Map.Draw()
  at MapBase.DrawAllViews()
  atGameForm.Run()
  at Project.Main()

Which to me seems like it's unable to load anything.

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Saving Game
« Reply #3 on: 2008-03-22, 06:50:18 PM »
UPDATE: I added the "Include Counters' and "include Current Map" rules to the saving function. Now when I can load a game, but it just restarts the map that i had last saved on.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Saving Game
« Reply #4 on: 2008-03-23, 07:33:52 AM »
Were you including anything else before?  Or did you not have any includes added when saving?
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Saving Game
« Reply #5 on: 2008-03-24, 05:21:24 AM »
A Fatal error occured initializing or running the game:
[...]
Which to me seems like it's unable to load anything.

It looks like the spikes sprite might be in an invalid state.  What determines the state that the spikes are in?

UPDATE: I added the "Include Counters' and "include Current Map" rules to the saving function. Now when I can load a game, but it just restarts the map that i had last saved on.

Maybe you are using some counter to set the state of the spikes, and it got a value on some map that was not valid for the spikes that are on the map that loads when you restart?

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Saving Game
« Reply #6 on: 2008-03-24, 10:57:51 AM »
No, the only counters I have right now are for basic inventory stuff (like "CastleKey" or whatnot). I took out both the 'includes' for now so I can load the game while playing it, but I still can't load a game from the title screen. The 'spikes' sprites have four states - Left, Right, Up, Down, that I would select when adding them inside the map editor.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Saving Game
« Reply #7 on: 2008-03-24, 12:19:18 PM »
I don't think I can understand the problem without seeing it myself.  Maybe you could post it somewhere or submit it to the support site.

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Saving Game
« Reply #8 on: 2008-03-24, 12:27:13 PM »
Alright. I'll submit it to the support page.
When testing, remember that Button 1(Ctrl) = Sprint
Also, how do you display a message on the screen?

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Saving Game
« Reply #9 on: 2008-03-25, 04:20:46 AM »
there is a custom code object, "showMessage". it must be already built in, because i can't find it at enigmadream.
btw, durnurds cool sprite definition "ShootInRange" isn't there, too.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Saving Game
« Reply #10 on: 2008-03-25, 05:44:26 AM »
OK, I got the project.  I'll look at it as soon as I get a chance.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Saving Game
« Reply #11 on: 2008-03-25, 05:27:11 PM »
That turned out to be kind of a bug in SGDK2.  It's having a problem because it expects that all the sprites that are loaded from a saved game have been initialized by the already-running game.  To work around it you can:
1) Add one of every type of sprite to the title screen (that isn't already on the title screen) OR
2) Start on some other map that has all the sprite types on it (though you don't need the sprites from the title screen) before switching to the title screen.

It's only a problem if a loaded game causes sprite types to be active that have never been active since the program was started.  It's not a problem if they are created after or before the game was loaded; only if the only thing that created them was loading the game.

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Saving Game
« Reply #12 on: 2008-03-25, 10:07:55 PM »
I tried method #2 and it worked. Thanks a lot! After I finish working on the first boss maybe I'll put out a demo of what I have so far.