Stopping unwanted message

Started by Anarcho, Tue 04/03/2008 03:36:51

Previous topic - Next topic

Anarcho

I feel like there is an obvious solution to this but I'm a little stumped.  I've got a little puzzle where if a person puts in 3 drops something happens.  I then want a default message if the player tries to put in more drops than necessary.  My problem is that with the code below, the game displays the default "There is no need to add anymore of this chemical" message right after the "You notice a small fizzle emanating from the new compound" message.  I feel like I knew how to do this under the old system but now I'm just rusty...

Thanks

Logan

  if (cEgo.ActiveInventory == iDropperPurple) { //

      if (myCounterPurple <3){
      cEgo.AddInventory(iDropper);
      cEgo.LoseInventory(iDropperPurple);
      myCounterPurple += 1;
      }
   
      if (myCounterPurple == 3){
      cEgo.AddInventory(iDropper);
      cEgo.LoseInventory(iDropperPurple);
      myCounterPurple += 1;
      myCounterFlask += 1;
      Display("You notice a small fizzle emanating from the new compound.");
      SetGlobalInt(163, 1);
     
      }
      if (myCounterPurple > 3){ 
      cEgo.AddInventory(iDropper);
      cEgo.LoseInventory(iDropperPurple); 
      Display("There is no need to add anymore of this chemical.");
      }   
}


TheJBurger

Change:
Code: ags
      if (myCounterPurple > 3){  

to:
Code: ags
      else if (myCounterPurple > 3){  

That should fix it.

GarageGothic

JBurger beat me to it, but as I was explaining while he posted:

The problem is that you're adding 1 to myCounterPurple within the subroutine. So if (myCounterPurple == 3), you get the fizzle message, but since you're adding 1 to the value, it's now 4, so (myCounterPurple > 3) will also register as true and give you the "no need to add more" message.

"else if" is indeed your friend.

Anarcho

#3
I love "else if"!  Thanks so much.


Khris

Btw, you can shorten the code to:

Code: ags
  if (cEgo.ActiveInventory == iDropperPurple) { //

    if (myCounterPurple < 3){
      cEgo.AddInventory(iDropper);
      cEgo.LoseInventory(iDropperPurple);
      myCounterPurple++;
      if (myCounterPurple == 3){
        myCounterFlask++;
        Display("You notice a small fizzle emanating from the new compound.");
        SetGlobalInt(163, 1);
      }
    }
    else Display("There is no need to add anymore of this chemical.");

  }


I've changed it slightly, too. The player won't empty the dropper if there are already three drops in the flask and he also can't put a fourth drop in.

SMF spam blocked by CleanTalk