Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Akumayo on Sat 14/01/2006 20:13:33

Title: Trouble with GP_NUMINVITEMS (SOLVED)
Post by: Akumayo on Sat 14/01/2006 20:13:33
Ignore the below posts, they are about a different problem.Ã,  My problem now is with GP_NUMINVITEMS.Ã,  I have this:
Ã,  Ã,  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?
Title: Re: Trouble with "while" function
Post by: DoorKnobHandle on Sat 14/01/2006 20:15:17
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.
Title: Re: Trouble with "while" function
Post by: Akumayo on Sat 14/01/2006 20:17:50
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  :):

    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:
overwhat = 0;

ERROR:  Unexpected 'overwhat'
Title: Re: Trouble with "while" function
Post by: DoorKnobHandle on Sat 14/01/2006 20:20:18
Yep, check your brackets. You have one closing bracket too much in there!!
Title: Re: Trouble with "while" function
Post by: Akumayo on Sat 14/01/2006 20:22:37
Ahh, I see it!  Thanks dkh  ;D
Title: Re: Trouble with GP_NUMINVITEMS
Post by: Akumayo on Sat 14/01/2006 21:22:55
New problem, see top post.
Title: Re: Trouble with GP_NUMINVITEMS
Post by: DoorKnobHandle on Sat 14/01/2006 21:35:47
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:

int overwhat = 0;


to this:


int overwhat = 1;
Title: Re: Trouble with GP_NUMINVITEMS
Post by: Akumayo on Sat 14/01/2006 21:40:56
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?
Title: Re: Trouble with GP_NUMINVITEMS
Post by: DoorKnobHandle on Sat 14/01/2006 21:44:48
Hmm... Strange. Then you should do some debugging. Comment out the passage if code that creates errors and add this line before:


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... ;)
Title: Re: Trouble with GP_NUMINVITEMS
Post by: Akumayo on Sat 14/01/2006 21:49:43
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...  ???
Title: Re: Trouble with GP_NUMINVITEMS
Post by: DoorKnobHandle on Sat 14/01/2006 21:52:28
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!
Title: Re: Trouble with GP_NUMINVITEMS
Post by: Akumayo on Sat 14/01/2006 21:55:16
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!
Title: Re: Trouble with GP_NUMINVITEMS
Post by: Pumaman on Sat 14/01/2006 22:04:13
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) );
Title: Re: Trouble with GP_NUMINVITEMS
Post by: DoorKnobHandle on Sat 14/01/2006 22:06:23
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... :=
Title: Re: Trouble with GP_NUMINVITEMS
Post by: Akumayo on Sat 14/01/2006 22:08:40
Ah, thanks CJ.

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

We were having quite a struggle with it...