ID:150163
 
OK, in my code, I want it so that when you click on a certain object, that you first walk to within 1 tile of it, then it moves to your location. I tried:
walk_to(usr,src,1,2)
if(src.loc == src.norm_loc)
src.loc = usr.loc
src.icon_state = "normal"
else
usr << "Object is already trashed."
return 0

With this code, the location of the object changes to the location of the user, but the user doesn't walk to the object first. I had tried using a variable to check the to make sure walk_to was completed first (i assumed it returned 1), but that didn't work due to the fact that walk_to() returns after every step.

Next, I tried using a do/while loop, walk_towards, and get_dist to do the walk_towards while the distances was greater than 1 but that caused BYOND to think it was an infinite loop and have my CPU waste 4 seconds on it.

Your thoughts and suggestions are much appreciated... this has been bugging me fore a couple days. :(

Thanks in advance,
Kev
Evilkevkev wrote:
Next, I tried using a do/while loop, walk_towards, and get_dist to do the walk_towards while the distances was greater than 1 but that caused BYOND to think it was an infinite loop and have my CPU waste 4 seconds on it.

You're on the right track with this. The problem with using walk_to and friends is that the walk_* procs execute in the background. They return immediately before you've even really taken the first step, so you can't assume that you've reached the destination by the time oyu hit the next line of code.

Instead, use step_to in combination with your while loop. Then you can do something like
while (get_dist(usr, src) > 1))
step_to(usr, src, 1)
sleep(5) // or whatever delay you want

Untested, but it ought to work fairly well.
In response to Air Mapster
Thank you! Thank you! Thank you!