Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kweepa on Sun 09/10/2005 16:07:34

Title: Plugin programming: deciding if a sprite exists
Post by: Kweepa on Sun 09/10/2005 16:07:34
I want to step through all the sprites in the game from my plugin.
This is the code I have:

          // global
          int s = 0;

          // in on_key_press
          bool exists = true;
          do
          {
            s++;
            if (s > 1000) s = 0;
            exists = true;
            try
            {
              BITMAP *agsBitmap = engine->GetSpriteGraphic(s);
              if (!agsBitmap || agsBitmap->w <= 0) exists = false;
            }
            catch (...)
            {
              exists = false;
            }
          }
          while (!exists);


It seems that GetSpriteGraphic can return non-NULL for nonexistent sprites, so I added the try/catch block to catch an access violation in agsBitmap->w. Unfortunately at some point GetSpriteGraphic throws an exception which AGS catches - out of sprite cache bounds.

Is there an easier way to do what I want to do? I don't want to resort to telling the plugin what the valid sprites are.

Cheers!
Title: Re: Plugin programming: deciding if a sprite exists
Post by: Pumaman on Mon 10/10/2005 18:37:04
There isn't an easy way to do this, no. I'm not sure why you'd need to iterate through every sprite in the game?
Title: Re: Plugin programming: deciding if a sprite exists
Post by: Kweepa on Mon 10/10/2005 19:55:56
It's part of the Ags3d editor (or it will be, hopefully) - reassigning textures on the fly.