Author Topic: Saving & Script  (Read 5130 times)

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Saving & Script
« on: 2007-01-18, 10:47:07 PM »
Well, we've made a lot of progress, but now I'm having trouble with my game saving stuff. What I noticed is this: when I tried to load a game in the 2nd map (where I created the definitions), I got an error saying it couldn't find a template. After a little more trial, I found it would load everything in the first map (where it's all predefined), but I got a little strange behavior. The ability to throw the spear is dependent on a variable (have_spear). I found that when I load the game, I can't throw it.

What all this leads me to believe is that the script variables aren't saved with the game. (A) Is this the case, and (B) how do I fix it?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Saving & Script
« Reply #1 on: 2007-01-19, 08:20:23 AM »
A: Yes, this is the case.  The only thing that is saved is the current state of the maps, inventory, and sprite locations... I think.

B: If there is any way to find out if have_spear should be set, based on these things, you can simply check those variables (like, for example, what map you're on, or if you have a certain inventory item) and set have_spear to true if you should.  If you can't derive its value based on saved settings, you should add an invisible inventory item to be saved with the project that is always equal to whatever have_spear is (1 for TRUE, 0 for FALSE).
Edward Dassmesser

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Saving & Script
« Reply #2 on: 2007-01-19, 10:17:15 PM »
Oh, man. That means all the sprites and definitions won't be reloaded...

I guess that's ok. I'm already getting an idea for a work-around.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Saving & Script
« Reply #3 on: 2007-01-20, 12:39:38 PM »
I should have been more broad.  Anything stored in memory in the project itself is saved, I believe.  So any sprite definitions that you have added to the project and any sprites you've added to the map will be saved.
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 & Script
« Reply #4 on: 2007-01-20, 01:39:39 PM »
If I were you I would remove have_spear as a script variable and just have the script look at the value of a counter... er Inventory Item to determine if the player should be able to throw a spear.  That would get automatically saved and loaded.

Did you notice that "counter" ... I guess I'm all excited about the SGDK2 alpha finally being out  8).  I hope you all run over and try it... gently :) (It is still undergoing testing, fixing and improvements).

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Saving & Script
« Reply #5 on: 2007-01-20, 05:04:03 PM »
Hmm... Now that IS odd... It was giving me an error message saying it couldn't find a sprite template. Is that supposed to be stored?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Saving & Script
« Reply #6 on: 2007-01-20, 05:18:42 PM »
I'm going to guess that you created and used a sprite template without adding it to the map.  Only objects that can be referenced under the "ProjectObj" hierarchy are saved, so local script variables are not saved.  Sprite templates, for example, are accessible via ProjectObj.Maps(N).SpriteTemplates.  But it will not be accessible that way if you "manually" create one and use it without adding it to the map with ProjectObj.Maps(N).AddSpriteTemplate.  Once you add it to the project, then it should be accessible via the collection in the map, and then would also be saved with the project.

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Saving & Script
« Reply #7 on: 2007-01-20, 06:03:38 PM »
Ok, templates are now added, but I'm getting a new problem: whenever the saved file is about to be loaded, it tells me it can't find the path "player_1". That's the player's path, so it's kinda important. I know the path's there, it just sort of disappears when I try to load the game.

Is there anything you can think of that may cause this?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Saving & Script
« Reply #8 on: 2007-01-21, 08:24:36 AM »
If you copied the player template and definition to other maps, but didn't put the player's path on those maps, I imagine it would have difficulty trying to connect the player sprite definition to its path while loading the game.  Each player sprite definition knows it needs to be connected to a path called "Player_1" on the map where the sprite definition is defined, but it probably can't find it on some of the maps where it was copied without the path also being copied to the map (with Map.AddPath).