SOLVED...Need help with Multiple If's and an Else

Started by NickyNyce, Fri 13/05/2011 21:52:29

Previous topic - Next topic

NickyNyce

sorry for having to post, I'm going to feel very embarrased when i see where I'm going wrong here, Pretty sure this is easy fix. Been hunting for answer for hours..

I would like to use an inventory item on an object or hotspot and have one response and have another inventory item say something else, after that i would like any other item to say something like That don't work. Everything work's ...except... when i use iClog and iPlunger, my guy is still saying the else line at the very bottom...I'm leaving the garbage code in the middle just in case you need to see it. Smoke is coming out of my ears, please help

function oTub_UseInv()
{
 if(cGuy.ActiveInventory==iClog){
 cGuy.Walk(618, 281, eBlock, eWalkableAreas);
 cGuy.FaceLocation(598, 176, eBlock);
 cGuy.Say("I hope this work's or my brother is gonna kill me");
 cGuy.LoseInventory(iClog);
 Wait(30);
 PlaySound(2);
 oTub.Visible=false;
 oEmpty.Visible=true;
 Wait(40);
 cGuy.Say("It's working, the water........AND MY RING...OH NO, NOT MY GRANDFATHER'S RING...it just went down the drain");
 cGuy.FaceLocation(618, 481, eBlock);
 cGuy.Say("Oh no, I can't believe it, I just lost my grandfather's ring that my dad gave me");
 cGuy.Say("I must have dropped it in the tub this morning when i showered, I have to get it back before they get home");
}
else if(cGuy.ActiveInventory==iPlunger){
 cGuy.Walk(570, 281, eBlock, eWalkableAreas);
 cGuy.FaceLocation(570, 176, eBlock);
 PlaySound(12);
 Wait(100);
 PlaySound(12);
 Wait(100);
 cGuy.Say("I used the plunger but the water still won't go down, now what?");
}
else   cGuy.Walk(570, 281, eBlock, eWalkableAreas);
 cGuy.FaceLocation(570, 176, eBlock);
 cGuy.Say("That don't work");
}

I also tried (If) and then using (If) for the plunger also, with else at the end and i'm still having the same problem. Sorry such a long post

Snarky

#1
The braces on the last else clause don't match up. Specifically, you're missing an opening brace. Ooops, no, that's not it. I misread the code since it's not indented correctly.

... Oh, I guess that was it after all. Seriously, you need to indent your code according to the nesting. And personally I prefer having the opening braces on a line by themselves, so that it's easy to verify that the nesting and indenting matches (and just for the symmetry of it).

Code: ags

function oTub_UseInv()
{
  if(cGuy.ActiveInventory==iClog)
  {
    cGuy.Walk(618, 281, eBlock, eWalkableAreas);
    cGuy.FaceLocation(598, 176, eBlock);
    cGuy.Say("I hope this work's or my brother is gonna kill me");
    cGuy.LoseInventory(iClog);
    Wait(30);
    PlaySound(2);
    oTub.Visible=false;
    oEmpty.Visible=true;
    Wait(40);
    cGuy.Say("It's working, the water........AND MY RING...OH NO, NOT MY GRANDFATHER'S RING...it just went down the drain");
    cGuy.FaceLocation(618, 481, eBlock);
    cGuy.Say("Oh no, I can't believe it, I just lost my grandfather's ring that my dad gave me");
    cGuy.Say("I must have dropped it in the tub this morning when i showered, I have to get it back before they get home");
  }
  else if(cGuy.ActiveInventory==iPlunger)
  {
    cGuy.Walk(570, 281, eBlock, eWalkableAreas);
    cGuy.FaceLocation(570, 176, eBlock);
    PlaySound(12);
    Wait(100);
    PlaySound(12);
    Wait(100);
    cGuy.Say("I used the plunger but the water still won't go down, now what?");
  }
  else
  {
    cGuy.Walk(570, 281, eBlock, eWalkableAreas);
    cGuy.FaceLocation(570, 176, eBlock);
    cGuy.Say("That don't work");
  }
}

NickyNyce

#2
TY Snarky, I'm very embarrased right now like i said i would be, thanks so much, all is well now, the smoke has cleared...

I will work on cleaning things up ...Thank's so much for taking the time, it's greatly appreciated...and will be remembered.

monkey0506

I'd just like to point out (again), that unless you're copying and pasting the vast majority of your code, AGS already indents it properly. Which is why I don't understand why this is such a persistent problem for people. Do they really use that much pasta in their code, or are they for some reason intentionally going out of their way to rape the formatting? I honestly don't know, but it puzzles me to no end.

Also, this makes me think of a suggestion for the editor..

NickyNyce

#4
Monkey, ...I will clean up the code, I'm still in the learning process here and understand now that this is a NO NO and why stupid problems happen...I see what you mean. I deserve the bashing and will learn from it.

SMF spam blocked by CleanTalk