Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: dbuske on Thu 21/06/2012 15:42:42

Title: If else-- solved
Post by: dbuske on Thu 21/06/2012 15:42:42
Ok, I have a puzzle that the main character must give the other characters
a correct inventory item.
If they give a wrong item, then I need to have the game return without crashing.
I checked the help on disk and online
I was unable to make it work.
I used inventory on a character and I assume if the correct inv is not given
I need to use, if else.
I do the game on my other computer now which is not net enabled yet.
If I have to, I can copy what I have to a blank cd and transfer it over. I would rather not.
Title: Re: If else
Post by: Andail on Thu 21/06/2012 15:47:21
Just use "else" if you're not introducing another condition. Also, please provide more info when asking for help, and the code used :)
Title: Re: If else
Post by: Matti on Thu 21/06/2012 15:56:23
Yeah, just use else like this:

Code (AGS) Select

function character_UseInv()
{
  if (player.ActiveInventory == iCorrectItem) {
    ...
  }
  else {
    ...
  }
}

You can use "else if" in case you have more than two conditions:

Code (AGS) Select

  if (player.ActiveInventory == iBanana) {}
  else if (player.ActiveInventory == iApple) {}
  else if (player.ActiveInventory == iPhone) {}
  else {}

Title: Re: If else
Post by: Khris on Thu 21/06/2012 17:14:17
And:
http://www.adventuregamestudio.co.uk/manual/ifelsestatements.htm
Title: Re: If else
Post by: dbuske on Thu 21/06/2012 20:15:33
Thanks, like I said I did read the if else documentation.
I will try it out now.  It is greek to me right now.
Title: Re: If else
Post by: Khris on Thu 21/06/2012 20:50:15
Just go at it step by step.
It's either:
if (CONDITION) {COMMANDS} else {COMMANDS}
or:
if (CONDITION) {COMMANDS} else if (CONDITION) {COMMANDS} else {COMMANDS}

That's plain English and simple logic. Programming doesn't get much easier than that.


Title: Solved
Post by: dbuske on Fri 22/06/2012 18:56:19
It is solved.  Thanks everyone.