Need some help with this code

Started by Candle, Sun 30/01/2005 02:43:06

Previous topic - Next topic

Candle

I can't do code when it gets the if and else in it .
How would I do this so if they have inventory 25 they go to room 7 and if they have inventory 26 they go to rom 8  ?

if (GetGlobalInt(1) == 5) {   
   NewRoomEx(7,42,52);

}
if (GetGlobalInt(1) != 5) {
   NewRoomEx(8,42,52);

}

TerranRich

#1
Candle, instead of using two if's, replace the second if block with "else {"...

And I've also noticed that you've set a new world's record for number of questions asked in the Beginners' Forum. You might get an award or something. :P But seriously, do you need some help with scripting in general? There are tutorials for coding in general, and coding specifically within AGS. They can be found in the manual itself, and from the AGS home page, under "Tutorials".

As for your question, make an "if" statement such that:

Code: ags
If Player Has Inventory #25
{
  Go to Room 7;
}
Otherwise, if player has inventory $26
{
  Go to Room 8;
}


I want to see if you can do it yourself, Candle, and I'll help you out. Hint: Look in the manual for the scripting sections on Rooms and Inventory functions. The thing is, you have to think about something. Will the player always have either one of the two items at this point? Is there ANY way that the player can have neither? Because if so, neither statement will run. If there is a possibility that the player can have neither inventory item, then you must account for that by addiing a generic "else" block after that.
Status: Trying to come up with some ideas...

Candle

Thanks TerranRich , No he will only have one or  other . I have him start with one and if He grabs the other it deletes the one he started with .
I'm trying to remember but my memory is so bad I forget things to fast .
If you want to know more just PM .
Thank you for the help .

Candle

#3
I think I'm close but I'm getting and if statement about missing if ?
Code: ags
  // script for region5: While player stands on region
 if ((player.inv[26] == 1) || (player.inv[26] == 1)) {   
    NewRoom (7); 
  } 
}
 if ((player.inv[25] == 1) || (player.inv[25] == 1)) {   
    NewRoom (8); 
  } 
}


Got it to work with this
Code: ags

if ((player.inv[26] == 1) || (player.inv[26] == 1)) {   
    NewRoomEx(7,40,24); 
  }

I just have it so I can use two items .

TerranRich

Um...basically, what you have there is "If player has inventory #26, or if player has inventory #26...". Why do you have two of them connected with "OR" (||)? Also, the proper way to use if-statements is to format it like this:

Code: ags
IF something
{
  Do Something;
}
ELSE IF something
{
  Do Something for Another Condition;
}
ELSE
{
  Whatever Else, Do This;
}


However, you don't always need the last ELSE. But it's better to use IF - ELSE IF - ELSE IF, etc.

Finally, pay attention to your braces. This is one problem you always seem to have. Count all of you opening braces ({) and closing braces (}). They should be the same, If not, look closely and see where you went wrong.

Spoiler

If you don't want to bother looking, you have two closing braces after each NewRoom() statement. You only need one each, to close off both IF blocks.
[close]

Hope that helped. And don't double post...edit your original post. ;)
Status: Trying to come up with some ideas...

Candle

Well I want to leave  it with the 26    26 that way if I add something I can .
Thank you for your help . I will forget this but I did try .. lol
I write things down but lose it and can't find what I wrote down .

TerranRich

It's ok. Just remember that CJ (Pumaman) has made some scripting tutorals on the AGS main page, if you ever want to take a look.
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk