ID:178900
 
I have a question on the behavior of spawn.

I have a verb that uses spawn to delay 5 seconds.

When I use this code
verb
dock()
set src in view(1)
usr << "Please wait while your ship is docked!"
spawn(50)
usr << "Your ship is now docked!"

All is fine the first message in displayed and then 5 seconds later the second message is displayed.

When I try to set a variable after the spawn like this

verb
dock()
set src in view(1)
usr << "Please wait while your ship is docked!"
spawn(50)
usr.docked = 1
usr << "Your ship is now docked!"

It displays both messages right away and then starts the timer. After 5 seconds the usr.docked variable is set to 1 I have modified my move proc to check the docked variable and not allow the player to move if it is 1. This allows the player to move for 5 seconds until the usr.docked variable is set.

From what I read about spawn the above code should do this
Display first message
wait 5 seconds
set usr.docked to 1
display last message.

Can anyone clear up why this is doing this?


It looks like the problem is indention.

Try something like this:

verb
dock()
set src in view(1)
usr << "Please wait while your ship is docked!"
spawn(50)
usr.docked = 1
usr << "Your ship is now docked!"


Also, note that if you had left your code indented as it was, you could have used sleep() instead of spawn().

-AbyssDragon