ID:143706
 
Code:
mob/var/test

mob
verb
Test()
set name = "Test"
set category = "Test"
if(usr.test == 1)
usr.test = 0
usr << " OFF!"
else
usr.test = 1
usr << "ON!"
flick("test",usr)
usr.invisibility = 1
if(usr.dir == NORTH)
usr.loc = locate(usr.x,usr.y+1,usr.z)
if(usr.dir == SOUTH)
usr.loc = locate(usr.x,usr.y-1,usr.z)
if(usr.dir == EAST)
usr.loc = locate(usr.x+1,usr.y,usr.z)
if(usr.dir == WEST)
usr.loc = locate(usr.x-1,usr.y,usr.z)
usr.invisibility = 0
flick("test",usr)


Problem description:

:P Continuous, what a word. I'm not going to lie, I had to look that one up. lol

Anyways! So I would like some assistance on what I can only assume would be looping. When I click test I want to move in the direction continuously until I click the verb again to stop it. Sounds easy enough, no? Well... I can't figure it out, and any help would be great. :D
You'll want to look into the while()(http://developer.byond.com/docs/ref/info.html#/proc/ while) and step()(http://developer.byond.com/docs/ref/info.html#/proc/ step) procs.


Here's a very simplified version of how you might do this. Might not be perfect, but it's a start at should give you an idea.
mob/verb/Test()
set name = "Test"
set category = "Test"
if(usr.test)
usr.test = 0
usr << " OFF!"
else
usr.test = 1
usr << "ON!"
flick("test",usr)
usr.invisibility = 1
while(usr.test)
sleep(10) //You'll want some kind of delay, or they will go way too fast, and the loop will affect your game performance)
step(usr, usr.dir)
usr.invisibility = 0
flick("test",usr)
<dm>
In response to Zagreus
Ah perfect, thanks for the links! :D





Carnia
In response to Zagreus
now how would you put something like that into a Client movement thing (like North South East West)? because im making a pacman game that something like this would be perfect for, but id need the northwest-northeast southwest-southeast parts disabled
In response to VolksBlade
spawn a loop that continuously steps the mob in whatever direction it is facing, override the client/North(), client/East, etc procs to do nothing more than change the mobs direction.

client/North()
mob.dir = NORTH


Override the diagonal movement keys to do nothing.
client/NorthEast()
return
In response to Zagreus
Awsome thanks!

im running a proc with your while() thing as soon as the person logs in, and its working ^__^

now onto those power pellets.. hmm
Using a loop for this IS NOT recommended, instead use the walk() function instead of step().
client/North()
walk(mob,NORTH,delay)
In response to Nadrew
Didn't think about that. Good idea.
In response to Nadrew
ummm whats the difference?
In response to VolksBlade
Wasted code lines, pointless overly difficult approach. Plus walk has the same effect anyway. Why remake a walk() proc XD.
In response to Pyro_dragons
Exactly.

Less room for mistakes, automatic setting in background, etc.

It CAN be done with a loop, and if you know what you're doing I'm sure you can do it cleanly and efficiently. But why re-invent the wheel?

Note in my case, I didn't exactly know the wheel existed. :/ I've used walk() once or twice, but it's not such a common proc that you always remember its existence like step().
In response to Zagreus
Really? I use walk alot, but then again my game is an RPG.