Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Atelier on Mon 20/04/2009 20:52:35

Title: Creating simple if statements
Post by: Atelier on Mon 20/04/2009 20:52:35
Hullo. I have not been using AGS for long, and already I have encountered lots of problems.
The latest concerns if statements. Here's what I would like to do:

If the player has picked up iPockettranslator, then I would like hCScreen activated, which, on any click, would take him to a new room. But, if the character has not yet found iPockettranslator then I don't want anything to happen when they click on the hotspot.

Here's the scripting that I have constructed for it:

function_RoomLoad ()
{
   hCScreen.Enabled = false ;
}
if (player.HasInventory (iPockettranslator)) {
   hCScreen.Enabled = true;
}
else {
   hCScreen.Enabled = false;
}

I have looked through the forums and almost know the entry on the manual off by heart (knowing me, I've overlooked something simple), although I don't know what is stopping me from running the game. A message usually comes up saying (Parse error: Unexpected if). I have entered this sequence in the room which the hotspot is located in. Do I need to transfer it to the global script? Also, do the two terms (roomLoad + else) contradict each other?

Vaguely linked to this (I think/hope) is the word bool. What does it mean and is it important in if/else?

Thank you for taking the time to read my query.
Title: Re: Creating simple if statements
Post by: JimmyShelter on Mon 20/04/2009 21:06:54
I have never coded in AGS, but I'm a programmer. What's wrong is the following: your if-statement is outside of your function.

Try this:


function_RoomLoad ()
{
   hCScreen.Enabled = false ;

   if (player.HasInventory (iPockettranslator)) {
      hCScreen.Enabled = true;
   } else {
       hCScreen.Enabled = false;
   }
}


Which you could even simplify to:

function_RoomLoad ()
{
   hCScreen.Enabled = false ;

   if (player.HasInventory (iPockettranslator)) {
      hCScreen.Enabled = true;
   }
}

Title: Re: Creating simple if statements
Post by: Atelier on Tue 21/04/2009 16:23:27
Thank you for replying.

I entered your code and it worked fine. Afterwards, I altered it a tiny bit to include some more features that I wanted, but without you I would still be wondering what was wrong. I should be able to use lots of if statements from now on!

Thank you again,

Francis de Mont