Trouble with GP_NUMINVITEMS (SOLVED)

Started by Akumayo, Sat 14/01/2006 20:13:33

Previous topic - Next topic

Akumayo

Ignore the below posts, they are about a different problem.Ã,  My problem now is with GP_NUMINVITEMS.Ã,  I have this:
Code: ags
Ã,  Ã,  overwhat = 0;
while (overwhat <= GP_NUMINVITEMS) {
Ã,  Ã,  Ã,  if (InventoryItem.GetAtScreenXY(mouse.x, mouse.y) == inventory[overwhat]) { 
//some stuff
overwhat ++;
//more stuff

In my script, however, I get an error saying the array index is 3, and the inventory items vars are 1-2.Ã,  I have created only two inventory items, and the while function SHOULD stop the script upon overwhat hitting 3 shouldn't it?Ã,  What's wrong now?
"Power is not a means - it is an end."

DoorKnobHandle

#1
Is this exactly how you have your script? 'Cause (if I'm not completely blind) everything is correct in there.

EDIT: Make sure you have your brackets ({ and }) correctly in those parts that you left out when posting here. It's likely to be a bracket-mistake.

Akumayo

Not exactly, but pretty darn close.  I was going to save on space, but what the hey.  I'll post the whole code, 'cause it all looks right to me here too.  Here it is, the full code this time  :):
Code: ags

    int overwhat = 0;
    ProcessClick(mouse.x, mouse.y, eModeWalkto);
    while (overwhat < 21) {
      if (Object.GetAtScreenXY(mouse.x, mouse.y) == object[overwhat]) {
        if (Mouse.IsButtonDown(eMouseLeft) == 1) 
          ProcessClick(mouse.x, mouse.y, eModeInteract);
        }
        if (Mouse.IsButtonDown(eMouseRight) == 1) {
          ProcessClick(mouse.x, mouse.y, eModeLookat);
        }
      }
      overwhat ++;
    }
    overwhat = 0;
    while (overwhat < 21) {
      if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[overwhat]) {
        if (mouse.IsButtonDown(eMouseLeft) == 1) {
          ProcessClick(mouse.x, mouse.y, eModeInteract);
        }
        if (mouse.IsButtonDown(eMouseRight) == 1) {
          ProcessClick(mouse.x, mouse.y, eModeLookat);
        }
      }
      overwhat ++;
    }


The error is generated by the line:
Code: ags
overwhat = 0;


ERROR:  Unexpected 'overwhat'
"Power is not a means - it is an end."

DoorKnobHandle

Yep, check your brackets. You have one closing bracket too much in there!!

Akumayo

"Power is not a means - it is an end."

Akumayo

"Power is not a means - it is an end."

DoorKnobHandle

Well, if I am not again completely mistaken, you have your "overwhat" variable going from 0 to 2 ( 0, 1 and 2 ) and then you said you have two inventory items created, that you try to call with the "overwhat" index. That means you try to access the inventory items 0, 1 and 2. But if you really only created 2 items, you will only have two valid items ( 1 and 2 ).

Just change this:
Code: ags

int overwhat = 0;


to this:

Code: ags

int overwhat = 1;

Akumayo

Changed, but alas, the exact same error occurs.  (Attempted your earlier/edited out code too, it also didn't work  :P)
This is quite frustrating no?
"Power is not a means - it is an end."

DoorKnobHandle

Hmm... Strange. Then you should do some debugging. Comment out the passage if code that creates errors and add this line before:

Code: ags

Display ( "Num Inventory Items: %d", GP_NUMINVITEMS );


Now run the game and see if it really says: "Num Inventory Items: 2"!

If it does, then I'm pretty at the end... ;)

Akumayo

oooooooooookay...... this is about the weirdest thing I've seen in AGS ever...
"Inventory Items = 12"

I really only have two in the editor... this is very strange to me... time to call in the "S-Team": Ashen, Strazer, Pumaman, go team S!

Seriously though... this is very strange.  I'm using the default game template, if that helps...  ???
"Power is not a means - it is an end."

DoorKnobHandle

That's what I though. This may be a bug in AGS. CJ will have to take a look at this.

You can work around it by replacing "GP_NUMINVITEMS" with "GP_NUMINVITEMS - 10" for now, this will return 2 instead of 12!

Akumayo

I already did that, and it causes another problem.  I created two more inventory items.  There's four now.  So the interactions only get run for 1 and 2, since it's minus 10.  CJ, we need you!
"Power is not a means - it is an end."

Pumaman

The problem is that this line:

while (overwhat <= GP_NUMINVITEMS) {

is checking for <=, but actually it should be <
The number that GP_NUMINVITEMS returns is actually one higher than the number of inventory items which is slightly confusing (I'll update the docs); so if you have two items it will return 3.

Also, you need to actually use GetGameParameter, you can't just compare to GP_NUMINVITEMS:
while (overwhat <= GetGameParameter(GP_NUMINVITEMS, 0 ,0, 0)) {


Quote
Display ( "Num Inventory Items: %d", GP_NUMINVITEMS );

This shows 12 because GP_NUMINVITEMS is the enum selector for what to return. I assume you mean:

Display ( "Num Inventory Items: %d", GetGameParameter(GP_NUMINVITEMS, 0, 0, 0) );

DoorKnobHandle

Ah, thanks CJ.

It'll be a good idea to mention that in the manual!

*note to self: don't ever try to help someone after drinking more than 1,5 liters of beer... :=

Akumayo

Ah, thanks CJ.

It'll be a good idea to mention that in the manual!

We were having quite a struggle with it...
"Power is not a means - it is an end."

SMF spam blocked by CleanTalk