ID:912609
 
(See the best response by Albro1.)
Code:
  proc/rattai()
if (src.hp>0)//del a mob takes more than hp<=0
for (var/mob/M as mob in view(5))
if (get_dist(M,src)<5)
step_away(src,M)
break
spawn(metab) rattai()


Question(s):
When I let this run and walk into the room with a ratt, he seems not to just step_away, but to also step_to (including walking right up to me)
Also, is spawn the best method here? I simply want the ratt to delay for his metab(olism) between each move.
And along these lines:
Code:
turf
Click()
nc=world.time
if (nc>=lc+usr.metab)
//spawn(usr.metab)
step_to(usr,src)
lc=world.time

Problem: This works fine as long as you don't mind clicking 400 times to walk 400 squares (and waiting for metab for each click!) I would rather this works more like walk_to with a delay (metab) between each step, with an allowance for if a new click is received.. and lc and nc are last click and new click, my variable names tend to be short.

Thanks in advance for any help you may provide
Some Slacker
Best response
Keep in mind that view() will have src in it's list. You can get around this by either using oview()(Which excludes the entire tile src is on - it may or may not be favorable for you) or by checking to make sure M is not src. I'm assuming rattai() is under the same type path as the ratt itself.

As for clicking with allowance for new clicks - just use a loop. Store the turf that was clicked last and have a loop make you step_to() the clicked turf and then delay between each iteration. Once you reach the destination, reset the clicked turf to null.
In response to Albro1 (#1)
Yep, you're right, I hadn't considered that the ratt was seeing itself, oview should indeed fix this up. Of course its not anywhere close to complete code, I don't have the ratt check at all what it is he's seeing, it might even be a frogg that should be nothing but food to the ratt and not something to fear and flee from...

And yeah, I had considered a loop checking to see if you had arrived at the clicked spot yet, but just wanted to make sure there wasn't an easier way...

Thanks for yer help Albro1
Glad to help.