DeleteSprite when saving games with screenshots [SOLVED]

Started by leone, Sat 27/11/2004 19:20:44

Previous topic - Next topic

leone

Hi guys, I need help.

I'm trying to implement the “save games with screenshots" feature into my game. I think I made it work except for the part about the use of DeleteSprite. When I overwrite or load a saved slot and leave the game I get a message like this:

QuoteDynamic sprite 2062 (or something) was never deleted

From the manual I gather that after LoadSaveSlotScreenshot I have to call DeleteSprite, but I don't know where and how exactly to use it. I tried to put it in the script where the function of the delete button is, cause I figured the screenshot should be deleted alongside the save slot. Then I thought I should use it whenever the save gui is closed. Either way I kept getting this message:

QuoteAttempted to free a static sprite that was not loaded by the script

Is the sprite that's supposed to be deleted the actual screenshot?

I checked out the thread from the technical archive and the scripting tutorial from Ezine, but I already made my own custom save and load guis so I couldn't just copy/paste the script. And I'm not too good at scripting (I came this far by taking bits and pieces from different sources), so I can't read these scripts with proper understanding and take what I need.
Mister No is coming

Radiant

You should call DeleteSprite (sprite) when you close the saved game window (because at that point, the sprite is no longer needed and can be removed from memory).
You should also do a DeleteSprite (sprite) before loading a new sprite, because otherwise you lose track of the old sprite.

leone

#2
Thanks Radiant.

OK, I went at it again and added DeleteSprite wherever I thought fit. And everything seems to be working fine now, except for one thing.

In my custom save and load guis I want the player to see the screenshot of the saved game when he clicks on its name in the list box. But after I leave the game afterwards I get a ‘Dynamic sprite was never deleted' message.

If I delete the sprite right after I show it in the appropriate button, the player never sees it. For the moment I inserted WaitMouseKey (200) in between, so that the screenshot is there at least for 5 seconds, or until the player presses something.Ã,  It looks like this (for the LOADGUI):

Ã,  else if (button==0) {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, // click on a save gameÃ,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  index=ListBoxGetSelected(LOADGUI,0);Ã,  Ã,  Ã,  // select it
Ã,  sprite = LoadSaveSlotScreenshot(savegameindex[index], 106, 49);Ã,  // load its screenshot
Ã,  Ã,  if (sprite != 0)Ã,  {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, Ã, // if there is a screenshot
Ã,  Ã,  Ã,  SetButtonPic(LOADGUI, 3, 1, sprite);Ã,  Ã,  Ã,  Ã,  Ã, // show it in button 3Ã,  Ã, 
Ã,  Ã,  Ã,  WaitMouseKey (200);Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, // wait
Ã,  Ã,  Ã,  DeleteSprite (sprite);Ã,  Ã, } Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, // delete spriteÃ,  Ã, 
Ã,  Ã, }

But that's not good enough. When the player clicks a savegame'sÃ,  name in the listbox, it's screenshot should appear in the appropriate button and stay there until you choose another slot or delete it, without disappearing by itself after awhile and disabling the mouse cursor.

Help?
Mister No is coming

Radiant

Try this:
Code: ags

 else if (button==0) {                                           // click on a save game                                   
    index=ListBoxGetSelected(LOADGUI,0);      // select it
    if (sprite != 0)  DeleteSprite (sprite);
  sprite = LoadSaveSlotScreenshot(savegameindex[index], 106, 49);  // load its screenshot
    if (sprite != 0)  {                                                // if there is a screenshot
      SetButtonPic(LOADGUI, 3, 1, sprite);         // show it in button 3   
   }


and also delete the sprite when you close the saved game window. Also, of course, sprite must NOT be a local variable to the interface_click function!

leone

#4
Thanks for trying to help, Radiant!

I tried your suggestion, but I got a

QuoteAttempted to free a static sprite that was not loaded by the script
message.

I gather I have to define 'index' and 'sprite' everytime before I try to DeleteSprite (sprite).Ã,  Is there a way for the program to memorize the number of the sprite that is loaded when the player clicks on a saved game, and then when he clicks on a different saved game or leaves the save gui, for them to be deleted?
Mister No is coming

leone

Just to let you know I took care of the problem thanks to Catsfan and his 'Leisure Suit Larry 2' template I found at www.freewebs.com/skimbleshanks/templates.htm.
Mister No is coming

SMF spam blocked by CleanTalk