If else-- solved

Started by dbuske, Thu 21/06/2012 15:42:42

Previous topic - Next topic

dbuske

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.
What if your blessings come through raindrops
What if your healing comes through tears...

Andail

Just use "else" if you're not introducing another condition. Also, please provide more info when asking for help, and the code used :)

Matti

Yeah, just use else like this:

Code: AGS

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

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

Code: AGS

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



dbuske

Thanks, like I said I did read the if else documentation.
I will try it out now.  It is greek to me right now.
What if your blessings come through raindrops
What if your healing comes through tears...

Khris

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.



dbuske

It is solved.  Thanks everyone.
What if your blessings come through raindrops
What if your healing comes through tears...

SMF spam blocked by CleanTalk