Non-Block Walk to point

Started by joelphilippage, Fri 10/09/2010 00:30:04

Previous topic - Next topic

joelphilippage

I'm trying to write a non block walk to script so one character can walk to a location and the player can switch and do something else at the same time.

Code: ags

function went(this Character*, int x, int y) {
  clicked = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  if (player.ID == 0){
    lx = x;
    ly = y;
    lPlayerGoing = true;
  }
  else{
    rx = x;
    ry = y;
    rPlayerGoing = true;
  }
  this.Walk(x, y);
}
function repeatedly_execute(){
  if(lPlayerGoing == true){
    if((cDuetL.x == lx) && (cDuetL.y == ly)){
      run = true;
      clicked.RunInteraction(eModeInteract);
      run = false;
      lPlayerGoing = false;
    }
  }
  if(rPlayerGoing == true){
    if((cDuetR.x == rx) && (cDuetR.y == ry)){
      run = true;
      clicked.RunInteraction(eModeInteract);
      run = false;
      rPlayerGoing = false;
    }
  }
}


This gets where the player needs to go and then checks when they get there. It will then re-run it's interaction code here:

Code: ags

if(run == true){
    player.Say("I'm here!");
  }
  else{
    player.went(31, 76);
  }


When the player get's to the location, it does not run the player.Say code.



Gilbert

I'm not quite sure, but it may be possible that the character does not reach the exact specified coordinates when he stops. You may try to check the character's Moving property instead.

Ryan Timothy B

A character only stops on even numbers. I had an issue with this as well when I wrote my non-blocking script.

There are two options, you could remove any odd number that you're telling it to walk. eg: player.went(31, 76);  to  player.went(30, 76);

Or you could have the script check if the number is odd and just subtract a number. eg:
Code: ags

function went(this Character*, int x, int y) {
  //this checks if x or y are odd and subtracts 1
  if (x & 1) x--;
  if (y & 1) y--;

  if (player.ID == 0){
    lx = x;
    ly = y;
    lPlayerGoing = true;
  }
  else{
    rx = x;
    ry = y;
    rPlayerGoing = true;
  }
  this.Walk(x, y);
}



And apparently my post count is telling me I'm 'leet'. Would you look at that!

joelphilippage

#3
Congratulations! I'm happy to have had a part in this momentous occation ;D. Thanks for your help. That would have taken me forever to figure out.

Edit: I had to fix a null pointer, but I could see that it was running the code. It's still not working though. (The player walks to the point and does nothing)




joelphilippage

I tried to use that module. I think if the player changes, it will not work anymore. I could use it as an example, but when the player gets to the point, nothing happens until I click again.



Khris

Yeah, changing the player without changing the room does indeed break my module.
Try __arrived = true; after changing the player.

SMF spam blocked by CleanTalk