SOLVED: pick up one object or the other, but not both at the same time

Started by Bryan_abos, Sun 10/09/2017 20:50:35

Previous topic - Next topic

Bryan_abos

The idea is to make the player character to pick up one of two items from the wall (a hotspot called hDisco1/hDisco2), but if he picks up the other, the character have to give back the item "iVinyl" to the wall. Since I used a hotspot for the thing on the wall, the idea was to make a piece of wall to hide that object (oWall1 / oWall2). The inventory items are respectively iVinyl1/iVinyl2.

Code: ags

function room_Load()
{
  oWall1.Visible=false;
  oWall2.Visible=false;
}

function hDisco1_AnyClick()
{
  if (MovePlayer(123, 120))
  player.FaceDirection(eDirectionUp);
  {
    if (UsedAction(eGA_LookAt)) {
      player.Say("['Nunca me faltes'][Antonio Rios]");
    }
    if (UsedAction(eGA_PickUp)) {
      if (player.HasInventory(iVinyl2)) {
        player.Say("Si me llevo los dos se pueden quebrar.");
        oWall1.Visible=true;
        player.AddInventory(iVinyl1);
        Wait(1);
        MovePlayer(234, 124);
        oWall2.Visible=false;
        player.LoseInventory(iVinyl2);
      }
      else 
      oWall1.Visible=true;
      player.AddInventory(iVinyl1);
    }
  }
}

function hDisco2_AnyClick()
{
  if (MovePlayer(234, 124))
  player.FaceDirection(eDirectionUp);
  {
    if (UsedAction(eGA_LookAt)) {
      player.Say("[Nunca me faltes][Antonio Rios]");
    }
    if (UsedAction(eGA_PickUp)) {
      if (player.HasInventory(iVinyl1)) {
        player.Say("Si me llevo los dos se pueden quebrar.");
        oWall2.Visible=true;
        player.AddInventory(iVinyl2);
        Wait(1);
        MovePlayer(123, 120);
        oWall1.Visible=false;
        player.LoseInventory(iVinyl1);
      }
      else 
      oWall2.Visible=true;
      player.AddInventory(iVinyl2);
    }
  }
}


EDIT: I forgot to say what was the problem (laugh)

this is what actually happens. the main character picks up the hotspot, the hotspot desappears, the item appears on the inventory. then, when the main character picks up the other hotspot, the main character says that she can only take one, gives back the one she has, and the corresponding iVinyl appears in the inventory. So far so good. The problem is that when I pick up the other hVinyl from the wall, both disks appear on the inventory. How do I make it to only have one item in the inventory at the time?

Scorpiorus

Not sure why you're making it a hotspot and not an object, but if you want it that way, the logic should probably go as follows:

Code: ags

function hDisco1_AnyClick()
{
    if (MovePlayer(123, 120))
    {
        player.FaceDirection(eDirectionUp);

        if      (UsedAction(eGA_LookAt))
        {
            player.Say("['Nunca me faltes'][Antonio Rios]");
        }
        else if (UsedAction(eGA_PickUp) && !player.HasInventory(iVinyl1))
        {
            if (player.HasInventory(iVinyl2))
            {
                player.Say("Si me llevo los dos se pueden quebrar.");
                oWall1.Visible=true;
                player.Walk(234, 124, eBlock);
                oWall2.Visible=false;
                player.LoseInventory(iVinyl2);
            }

            oWall1.Visible=true;
            player.AddInventory(iVinyl1);
            hDisco1.Enabled = false; // just in case!
            hDisco2.Enabled = true; // just in case!
        }
    }
}


Code: ags

function hDisco2_AnyClick()
{
    if (MovePlayer(234, 124))
    {
        player.FaceDirection(eDirectionUp);

        if      (UsedAction(eGA_LookAt))
        {
            player.Say("[Nunca me faltes][Antonio Rios]");
        }
        else if (UsedAction(eGA_PickUp) && !player.HasInventory(iVinyl2))
        {
            if (player.HasInventory(iVinyl1))
            {
                player.Say("Si me llevo los dos se pueden quebrar.");
                oWall2.Visible=true;
                player.Walk(123, 120, eBlock);
                oWall1.Visible=false;
                player.LoseInventory(iVinyl1);
            }

            oWall2.Visible=true;
            player.AddInventory(iVinyl2);
            hDisco2.Enabled = false; // just in case!
            hDisco1.Enabled = true; // just in case!
        }
    }
}


See if it works.


EDIT: still do consider making it an object instead of hiding background graphics with a "wall" object.

Creamy

Bryan, the problem with your code is that you give the vinyl 1 twice when the player has the vinyl 2 (and vice versa).

Quotestill do consider making it an object instead of hiding background graphics with a "wall" object.
You can also enable/disable hotspots.
 

Scorpiorus

Quote from: Creamy on Sun 10/09/2017 23:56:01You can also enable/disable hotspots.

Yeah, that's a good point. We may actually get a bug where the player can take inventory item multiple times, if the wall object doesn't cover the hotspot properly.

So it's probably a good idea to enable/disable hotspots even with the wall-object-approach. I've updated the codes to reflect this.

Alternatively, we could do an extra check to see if the player has already had that inventory item before adding one.

Kitty Trouble

Sorry wrong thread

Bryan_abos

great call guys! I never though of that. it works perfectly now and I hadn't even thought about avoiding that bug (laugh) Thanks a lot!!!

SMF spam blocked by CleanTalk