Walk to destination based on conditionals

Started by Andrea1992, Sun 07/06/2020 13:59:31

Previous topic - Next topic

Andrea1992

Hi, in this first function my character is walking to the specified coordinates, according to its position before he start to walk:

Code: ags

int loop;
function cajon_Interact()
{
  if (cPedro.x > 470)
  {
    cPedro.Walk(550, 620, eBlock, eWalkableAreas);
    loop = 1;
  }
  else
  {
    cPedro.Walk(400, 620, eBlock, eWalkableAreas);
    loop = 0;
  }
  cPedro.LockView(ViewUsar);
  
 //other things
}


I tried something similar with the following function, but this time, the character is always walking to the same destination, no matter the X coordinate he is at the beginning.
What am I doing wrong?

Code: ags

int loop4;
int Xcoor;
int Ycoor;
function hRio_UseInv()
{
  if(cPedro.x < 430)
  {
    Xcoor = 350;
    Ycoor = 720;
    loop4 = 0;
  }
  else if (cPedro.x > 890)
  {
    Xcoor = 970;
    Ycoor = 720;
    loop4 = 1;
  }
  else
  {
    Xcoor = 640; 
    Ycoor = 720;
    loop4 = 0;
  }
  if(cPedro.ActiveInventory == iBotella_vacia)
  {
    cPedro.Walk(Xcoor, Ycoor, eBlock, eWalkableAreas);
    cPedro.LockView(20);
    cPedro.Animate(loop4, 2, eOnce, eBlock, eForwards);
    cPedro.UnlockView();
    cPedro.LoseInventory(iBotella_vacia);
    cPedro.AddInventory(iBotellaAgua);
  }
}


Thanks!

Cassiebsg

I can't see anything wrong per se in it, maybe someone else with more experience can though.

- I would ask though which coords is cPedro always walking too?

And second, maybe take note of which coords he's at when it starts.
For that you could just add a display at the start of the function that shows exactly where's at: Display(String.Format("Pedro is at X: %d and Y: %d" , cPedro.x , cPedro.y)); (note that this code might have some flaws, since I'm typing it out of memory, but hopefully it's good enough for you to get it working).
There are those who believe that life here began out there...

Andrea1992

Thanks Cassiebsg,
That was very helpful.
I just assigned values to the "WalkToPoint" property of the hotspot when I created it (I never use that, don't know what happened, maybe I was just testing how it works).
Ans yes, walking to this point was the first thing he does when interacting with that hotspot.

Thanks again, have a lovely day!

Cassiebsg

Ah, I did that on my first game as well and as a result I ended getting a huge headache to debug it.  (laugh)
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk