Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Michael Zhu on Tue 15/04/2003 12:36:02

Title: If troubles
Post by: Michael Zhu on Tue 15/04/2003 12:36:02
I've tried to input a script which has:
if ((character blah inv(10) = 1) && etc etc {
  addinventory(2);
  loseinventory(1); }

into a "interact with hotspot" interaction, the program says something like "script isn't finished, missing }" but I did have the beginning if script { and the end }.
Is it esential to have an Else command after the if one?
Where do I put the If functions in a room?
Title: Re:If troubles
Post by: Ishmael on Tue 15/04/2003 12:43:26
if (character blah inv(10) = 1) && etc etc {
 AddInventory(2);
 LoseInventory(1); }

Try this...
Title: Re:If troubles
Post by: Erica McLane on Tue 15/04/2003 13:24:14
Or:
if ((character[blah].inv(10) = 1) && etc etc {
  AddInventory(2);
  LoseInventory(1);
}
Title: Re:If troubles
Post by: scotch on Tue 15/04/2003 14:58:16
Or:
if ((character[blah].inv(10) = 1) && etc etc) {
  AddInventory(2);
  LoseInventory(1);
}

it was missing a ) right?
Title: Re:If troubles
Post by: Michael Zhu on Thu 17/04/2003 07:03:33
I know the script, but where do I put it? In a hotspot? in a room script? Character Enter Screen Before/After Fade in?
Title: Re:If troubles
Post by: Gilbert on Thu 17/04/2003 07:43:10
You must use double "=" for comparison too:

if ((character[blah].inv(10) == 1) && etc etc) {
 AddInventory(2);
 LoseInventory(1);
}

About where to put the script, it just depends on what you want it to do. We can't help you unless you give more info.
Title: Re:If troubles
Post by: Michael Zhu on Fri 18/04/2003 06:35:25
The placement isn't a problem anymore.
When I enter:
-----------------------------------------------------
if (player.inv[3] == 1 )  {
  Display("You suck!" //or whatever
}
-----------------------------------------------------
the game works fine, but when I use multiple conditions such as:
---------------------------------
if ((player.inv[3] == 1) && (player.inv[5] == 1) && (player.inv[69] == 1))  {
  Display("Sixty nine. Hehe, dirty mud.");
}
--------------------------------------------------------
AGS says something about not being able to comprehend "Nested functions" or I'm missing a } in the script, which I have checked for {s and }s several times over. Is AGS mongilated or am I doing something wrong?
Title: Re:If troubles
Post by: scotch on Fri 18/04/2003 12:09:53
I've had that before.. it was actually because there was a } missing even if it didn't look like it.  Make sure you are looking at the entire room script rather than just the script for an interaction when you check, it's easier to see.

I think the nested funtion error is because you have missed the last } from a function so it thinks you're trying to create a new function inside the last one, which it can't do.