'MyCounter1'

Started by Bryan_abos, Mon 28/08/2017 19:28:36

Previous topic - Next topic

Bryan_abos

Hi guys.

I want to make my character to gather a couple of items (iBola and iMoney) in a room, so she can leave it. I'm using the MI style gui.
The tutorial has taken me this far.

Code: ags

int myCounter1;

function hPuerta_AnyClick()
{
  if (MovePlayer(291, 119))
  player.FaceDirection(eDirectionRight);
  {
    if(UsedAction(eGA_Open)) {
      if (myCounter1 == 0)
      {
        player.Say("No me puedo ir aún. Tengo mucho que hacer.");
      }
      if (myCounter1 == 1)
      {
        player.Say("Ganaste!");
      }
      if ((player.HasInventory(iMoney)) && (player.HasInventory(iBolap)))
      {
      myCounter1 += 1;
      }
    }
  }
}


However, when open the door (open hPuerta) after I got the items (iBola and iMoney) it doesn't display the message wanted (ganaste!), but the same one
it displayed without the items.

Snarky

#1
The way you've coded it, this is what should happen:
  • As long as you don't have both items, you'll say "No me puedo..." (and the value of myCounter will stay at 0)
  • The first time you click on it after you've got both items, you'll say "No me puedo..." since the counter is still zero, and then the counter will be set to 1
  • The second time you click on it after you've got both items, you'll say "Ganaste!" (since the counter is now 1), and then the counter will be set to 2
  • The third time, fourth time, etc. you click on it, you won't say anything (since the counter is neither 0 nor 1), and the counter will keep increasing
What you probably want is simply:

Code: ags
function hPuerta_AnyClick()
{
  if (MovePlayer(291, 119))
  player.FaceDirection(eDirectionRight);
  {
    if(UsedAction(eGA_Open))
    {
      if (player.HasInventory(iMoney) && player.HasInventory(iBolap))
      {
        player.Say("Ganaste!");
        // TODO: Leave room
      }
      else
        player.Say("No me puedo ir aún. Tengo mucho que hacer.");
    }
  }
}


Khris

You'll also want to swap lines 4 and 5 of that snippet, I guess.

SMF spam blocked by CleanTalk