ID:148315
 
Hey, I am working on adding "click movement" to once of my games. Currently I have this which works really good,

//click walking - fix speed and target icon
mob
var/c=0

client.Click(O)
usr.c=1
walk_to(usr,O)
var/o=image('blue.dmi',O,"3")
src << o
sleep(8)
usr.c=0
while(get_dist(usr,O) >0)
sleep(5)
if(usr.c==1)
del(o)
del(o)

client.Move()
usr << "no: Click to move."
//end click walking

Well it works great and even adds the X where he will move to, but it moves to that X going about 100mph. How do I slow this down? I have it so I can slow the character down if someone uses the arrow keys to move around :
//Adds move delay to mob
mob/var
speeding = 0
rundelay = 4 //Set this to different settings to control how slow the mob walks.

client/Move()
if(mob.speeding <= 0)
mob.speeding = 1
..()
sleep(mob.rundelay)
mob.speeding = 0
else
return


mob/Login()
speeding = 0
..()
//end move delay code

Thanks for any help!
Long-And-Questionable Option:

walk_to(Ref,Trg,Min=0,Lag=0)

Solving the speedy movement from the click is easy enough in theory because the walk_to() proc accepts a lag argument which will delay each movement step. (Use mob.rundelay?)

However, the movement controls add a little extra. Changes in lag would not be noticed until the next time the walk_to() proc is called. Movement buttons would be pressed, but the mob would not walk any faster until the next time something was clicked.

It might be useful to have a temporary var reference what was clicked. Then you could call the walk_to() proc again with a different lag value when movement buttons are pressed. Perhaps it would be useful to set the temporary value to null when the clicked target is reached.

Why-Am-I-Wasting-Your-Time-With-The-Above? Option:

That said, there is also a more common method which involves checking the time to allow/disallow movement in Move() procs. There are numerous threads in the BYOND forums about it. I picked [link] at random. (It mentions a BYONDscape article too, but I didn't see it.) You could then set the movement buttons to increase or decrease time between steps.


PS: Move() procs return a 1 on success and 0 on failure.
In response to ACWraith
Thanks for the help!