Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: BlueAngel on Fri 11/02/2011 13:23:12

Title: (Solved) Checking where a object is to pick it up
Post by: BlueAngel on Fri 11/02/2011 13:23:12
Help
I want the player to pick up something and I want the player to walk there to pick it up. But he can only pick it up if he can reach it.
What I’m I doing wrong here:  ???


function oCoconut_AnyClick()
{
 //LOOK AT
 if(UsedAction(eGA_LookAt)) {
   player.Say("It's a coconut");
   
 }
 // USE
 else if(UsedAction(eGA_Use)) {
   player.Say("I'd rather pick it up.");
 }
 // Push
 else if(UsedAction(eGA_Push)) {
   Unhandled();
 }
 // Pull
 else if(UsedAction(eGA_Pull)) {
   Unhandled();
 }  
 // PICKUP
 else if(UsedAction(eGA_PickUp)) {
         if(Object.GetAtScreenXY(525, 419)==oCoconut)
     {
       player.Say("Jummy");
       cEgo.Walk(525, 419, eNoBlock, eWalkableAreas);
   
       Hunger-=10;
    }
    else
    {
     player.Say("help");
     }
 }
 //USE INV
 else if(UsedAction(eGA_UseInv)) {
   Unhandled();
 }
 // don't forget this
 else Unhandled();
}


I also have this in the room:

function room_Load()
{
 short waveX = oWave.X;
 short waveY = oWave.Y;
 float duration = 3.0;
 oWave2.Transparency=20;
 oWave.IgnoreScaling = false;
 oWave.TweenPosition(duration,85, 639, eLinearTween, eRepeatTween);
 oWave2.TweenPosition(duration, 483, 411, eLinearTween, eRepeatTween);
 oCoconut.TweenPosition(10.0, 513, 384, eEaseOutTween,  eReverseRepeatTween);
 
   
}
Title: Re: Checking where a object is to pick it up
Post by: Khris on Fri 11/02/2011 14:42:48
You're using the 9verb template, right? There should be a function called MovePlayer you're supposed to use like this:

function oCoconut_AnyClick()
{
  if (MovePlayer(525, 419)) {
    player.FaceDirection(eDirUp);
    //LOOK AT
    if(UsedAction(eGA_LookAt)) {
      player.Say("It's a coconut");
    }
    // USE
    else if(UsedAction(eGA_Use)) {
      player.Say("I'd rather pick it up.");
    }
    ...
  }
}


Now, there used to be a small bug in MovePlayer which caused it to return true even if the player was unable to reach the specified coordinates.
Don't know if that has been fixed, I'm at work so can't take a look right now.
Title: Re: Checking where a object is to pick it up
Post by: BlueAngel on Fri 11/02/2011 14:45:11
Ok, I will try that when I get back in.
Thanks for helping me!
Title: Re: Checking where a object is to pick it up
Post by: BlueAngel on Sat 12/02/2011 08:42:38
No, it works but not as I want it to. cEgo walks to the coconut but can take it even when he shouldnt. Maybe I making this to hard. May I should just let the player have the coconut.  ::)

Is there any way else to check if a object is in a place beside this:

if(Object.GetAtScreenXY(525, 419)==oCoconut)

I have taken out the Tween moving so that not the problem as I thought..
Maybe I can do something with a timmer...


Solved it kind of:

// PICKUP
  else if(UsedAction(eGA_PickUp)) {
     if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&oCoconut.Animating==false)
  {
    cEgo.FaceObject(oCoconut, eBlock);
    cEgo.AddInventory(iCoconut);
  }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Animating==false)
    {
      player.Say("cant reach it");
    }


Now I just have to found another way to animate it without using Tween
Title: Re: (reopened) Checking where a object is to pick it up
Post by: BlueAngel on Sat 12/02/2011 10:22:54
I must be stupid.
With this code the player can never reach it even if he on region 1. Any suggestions?


// PICKUP
  else if(UsedAction(eGA_PickUp)) {
     if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&Object.GetAtScreenXY(525, 419)==oCoconut)
  {
    cEgo.FaceObject(oCoconut, eBlock);
    cEgo.AddInventory(iCoconut);
  }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Moving==false)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&oCoconut.Moving==true)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Moving==true)
    {
      player.Say("cant reach it");
    }
    else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&Object.GetAtScreenXY(525, 419)!=oCoconut)
    {
      player.Say("cant reach it");
    }
Title: Re: (reopened) Checking where a object is to pick it up
Post by: BlueAngel on Sat 12/02/2011 10:58:22
This works the first time but after the nut has move one time, it stops working  ???

// PICKUP
 else if(UsedAction(eGA_PickUp)) {
    if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&object[0].X==525)
 {
   cEgo.FaceObject(oCoconut, eBlock);
   cEgo.AddInventory(iCoconut);
 }
   else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&oCoconut.Moving==false)
   {
     player.Say("cant reach it");
   }
   else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&oCoconut.Moving==true)
   {
     player.Say("cant reach it");
   }
   else if(Region.GetAtRoomXY(player.x, player.y)!=region[1]&&object[0].X!=525)
   {
     player.Say("cant reach it");
   }
   else if(Region.GetAtRoomXY(player.x, player.y)==region[1]&&object[0].X!=525)
   {
     player.Say("cant reach it");
   }
   
 }

but it should be at the same place after move

function room_RepExec()
{
   if(IsTimerExpired(1))
 {
   oCoconut.Move(513, 384, 80, eNoBlock, eAnywhere);
   SetTimer(1, 400);
 }
 if(IsTimerExpired(2))
 {
   oCoconut.Move(525, 419, 20, eNoBlock, eAnywhere);
   SetTimer(2, 400);
 }
}


Close this -I think my problem was that the start position and my end position were too close so the picture of the object was overlapping or something. As soon as I put the end further down it worked.