Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: joelphilippage on Fri 10/09/2010 00:30:04

Title: Non-Block Walk to point
Post by: joelphilippage on Fri 10/09/2010 00:30:04
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.


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:


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.
Title: Re: Non-Block Walk to point
Post by: Gilbert on Fri 10/09/2010 01:59:02
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.
Title: Re: Non-Block Walk to point
Post by: Ryan Timothy B on Fri 10/09/2010 02:31:31
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:

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!
Title: Re: Non-Block Walk to point
Post by: joelphilippage on Fri 10/09/2010 04:10:12
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)
Title: Re: Non-Block Walk to point
Post by: Khris on Sat 11/09/2010 11:03:55
Try my module:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=36383.msg477380#msg477380
Title: Re: Non-Block Walk to point
Post by: joelphilippage on Sun 12/09/2010 21:22:57
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.
Title: Re: Non-Block Walk to point
Post by: Khris on Sun 12/09/2010 21:46:21
Yeah, changing the player without changing the room does indeed break my module.
Try __arrived = true; after changing the player.