Hi,
I have a background character named Kate who I would like to walk from one spot to another, repeatedly. The code I have does this -
function room_RepExec()
{
Kate.Walk(214, 356, eBlock, eWalkableAreas);
Kate.Walk(470, 351, eBlock, eWalkableAreas);
}
But the problem is, I can't control the player character and I have tried eNoBlock and it does not work,
Kate will the move one frame and freeze. How can I fix this?
Thank You.
Also, I have searched the manual and the forum exhaustively and could not find anything to help solve this.
Try something like this:
function room_RepExec()
{
if(Kate.x == 214 && Kate.y == 356 || !Kate.Moving)
Kate.Walk(470, 351, eNoBlock, eWalkableAreas);
else
if(Kate.x == 470 && Kate.y == 351)
Kate.Walk(214, 356, eNoBlock, eWalkableAreas);
}
The key with eNoBlock is that things happen asynchronously. Your code will tell the character to start walking eNoBlock and then the game will keep executing the room_RepExec every frame. That's why your character appeared to be staying in place or moving one frame and freezing. The above code will tell Kate to start walking eNoBlock only when Kate reaches a particular point on the screen. This is perhaps the most direct way to handle it. You could, for instance, have a more complex system where you toggle between her walking one way or the other if she gets stuck.
Thanks Gurok
I can now move my character around but Kate for some reason is walking on the spot. She is on a walkable area
so any idea how to fix that?
Edit: I am going to have to do some work in other areas of the game and come back to this, I entered the room, clicked on a fridge wich opens and
she started moving but stopped at the coordinates and didn't loop.
Oh whoops, I hadn't tested that code. Try this:
function room_RepExec()
{
if(!Kate.Moving)
if(Kate.x == 214 && Kate.y == 356)
Kate.Walk(470, 351, eNoBlock, eWalkableAreas);
else
Kate.Walk(214, 356, eNoBlock, eWalkableAreas);
}
Perfect!
Thank you very much Gurok, you've been a huge help, I can use this code for any other characters moving in the background.
Thanks again.