Benethe a Steel Sky GUI

Started by BuRRe, Sat 27/12/2003 00:31:51

Previous topic - Next topic

strazer

Hi all!

BuRRe, regarding v1.0 of your BASS-Interface.
I like it a lot, but I noticed something regarding the mouse wheel:

(I just got into scripting (and really must praise the excellent help file!), so don't slap me if I misunderstand this. ;D )

Here in the while-loop of your "on_mouse_click"-function, you manually set the number of inventory items via the variable (constant?) WHEEL_NUMBER_OF_ITEMS (defined in your script header):

...
else if(button == WHEELSOUTH)   // get previous possible inventory
   {
     lastInv--;
     invOrNormal = WHEEL_INVENTORY;
     while(character[GetPlayerCharacter()].inv[lastInv] == 0)
     {
       lastInv--;
       if(lastInv < 1)
         lastInv = WHEEL_NUMBER_OF_ITEMS;
     }
     character[GetPlayerCharacter()].activeinv = lastInv;
     SetCursorMode(MODE_USEINV);
   }
...

Why?
Isn't the global variable "game.num_inv_items" supposed to be used for that?
Thing is, if you character has no inventory (yet or s/he lost it or whatever),  the game crashes of course (endless loop), unless you constantly update the "WHEEL_NUMBER_OF_ITEMS"-variable:

(ACI version 2.60.693)
Error: run_text_script1: error -6 (Error (line 235): Script appears to be hung (150001 while loop iterations without an update)) running function 'on_mouse_click'


And another (minor) thing, regarding the same part of code above:
At the beginning of the game, the "lastInv"-variable is 0 (or null?) of course, since you haven't used the wheel yet.
Now if you scroll the wheel south, "lastInv" is -1 (lastInv--;, see above).
Since "character[GetPlayerCharacter()].inv[-1]" strangely returns "4" (not "0" as expected), no inventory items appear for 2 scrolls or so until it finally returns a "0" (I checked for -1 only).

I suggest changing it to

...
else if(button == WHEELSOUTH)   // get previous possible inventory
   {
     if (lastInv > 0)
       lastInv--;
...

to prevent that from happening.

Regards
strazer

P.S.: I signed on some time ago, but didn't post in quite a while. I tried to login again to post this, but my account was gone. Do accounts get deleted after (what?) time of inactivity?

Inkoddi

Nine months i think if you havent posted enough
toot

strazer

I have been working on this and have to correct myself here.

With the above code, when using the game.num_inv_items variable it doesn't activate the last inventory item but the inventory item that is the same number as the number of items in the inventory of course.
It just worked out that way when I tested it so I didn't notice it until recently.

So I've added the bold lines below.

...
else if(button == WHEELSOUTH)   // get previous possible inventory
   if (lastInv > 0)
      lastInv--;
   while(character[GetPlayerCharacter()].inv[lastInv] == 0) {
      lastInv--;
      if(lastInv < 1) {
         lastInv = WHEEL_NUMBER_OF_ITEMS;
         while(character[GetPlayerCharacter()].inv[lastInv] == 0)
            lastInv--;

      }
   }
   character[GetPlayerCharacter()].activeinv = lastInv;
   SetCursorMode(MODE_USEINV);
 }
...

WHEEL_NUMBER_OF_ITEMS is defined in the global script as the maximum number of inventory items there are in the game (or higher of course): #define WHEEL_NUMBER_OF_ITEMS 100

Is there an easier way to return the last (or first) item in the inventory?
It doesn't slow down or anything, I just don't like using too many loops.  :)

SMF spam blocked by CleanTalk