Author Topic: If else-- solved  (Read 305 times)  Share 

If else-- solved
« on: 21 Jun 2012, 15: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.
« Last Edit: 22 Jun 2012, 18:56 by dbuske »
What if your blessings come through raindrops
What if your healing comes through tears...

Andail

  • Global Moderator
  • Mittens Baronet
  • Cultured man of mystery
    • I can help with backgrounds
    •  
Re: If else
« Reply #1 on: 21 Jun 2012, 15:47 »
Just use "else" if you're not introducing another condition. Also, please provide more info when asking for help, and the code used :)
Be vigilant, citizen!
Check out my GiP, The Samaritan Paradox
Also, check my blog at http://faravidinteractive.wordpress.com/

Re: If else
« Reply #2 on: 21 Jun 2012, 15:56 »
Yeah, just use else like this:

Code: Adventure Game Studio
  1. function character_UseInv()
  2. {
  3.   if (player.ActiveInventory == iCorrectItem) {
  4.     ...
  5.   }
  6.   else {
  7.     ...
  8.   }
  9. }
  10.  
You can use "else if" in case you have more than two conditions:

Code: Adventure Game Studio
  1.   if (player.ActiveInventory == iBanana) {}
  2.   else if (player.ActiveInventory == iApple) {}
  3.   else if (player.ActiveInventory == iPhone) {}
  4.   else {}
  5.  

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: If else
« Reply #4 on: 21 Jun 2012, 20:15 »
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: If else
« Reply #5 on: 21 Jun 2012, 20:50 »
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.


http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Solved
« Reply #6 on: 22 Jun 2012, 18:56 »
It is solved.  Thanks everyone.
What if your blessings come through raindrops
What if your healing comes through tears...