ID:141510
 
Code:
                                                if(usr.Dive == 1)
usr.Move(locate(usr.x,usr.y,usr.z + 1))
usr.Dive = 0
usr<<"You ran out of breath"
return


Problem description: Well....usr.Move causes all the rest of the code after it to have a delay of 1-3 seconds before doing them,and it won't move the user if he is moving around....so i was wondering is there a better way of doing this. (I tried putting the usr.Move last but it just causes a small bug,and it still won't work if the user is moving around)

Well firstly, to keep your code robust instead of doing:

if(usr.Dive==1)


Do this:

if(usr.Dive)


As Dive is 1 it will be true and it will work in the same way.

Now to your problem, As the user is moving to the next Z level, there is no need to move, you could simply edit the loc like so:

usr.loc = locate(usr.x,usr.y,usr.z+1)


I think it takes time as you're moving to a different Z level, either that or you are doing extra processing at mob/Move().
In response to Haywire
He probably /should/ be using the Move() procedure to move between Zlevels - otherwise you could dive and end up in the same square as someone. Or worse, dive and end up encased in rock.

I suspect the issue is that he's handling move delays by putting a sleep() call in the Move() procedure. The solution: Do movement delays properly.

var/const/MOVE_DELAY_TIME = 10

atom/Movable
var
tmp/delay = 0 //tmp so we don't save it

Move()
if(delay) return 0 //Delayed - can't move
.=..() //Do the default procedure
delay = 1 //Set the delay
spawn(MOVE_DELAY_TIME) delay = 0 //Unset the delay in MOVE_DELAY_TIME ticks


Then your code for the Dive verb would just have to set usr.Delay to 0 before you called Move(). Better yet, add an extra argument to Move() that specifies you want to ignore movement delays - I'll leave that as an exercise to you.
In response to Jp
Makes sense, but why /should/ he? Move handles other things like ANIMATE_MOVEMENT, which animates the movements and that may effect speed where as locating directly would be a lot simpler. Also what's the need for move? It produces the same effect just a bit slower (not that it matters).

I may be wrong, please correct me if you so.
In response to Haywire
Move() calls Enter() and Entered() on the turfs. Setting a loc directly doesn't.
In response to Haywire
Haywire wrote:
Well firstly, to keep your code robust instead of doing:

> if(usr.Dive==1)
>

Do this:

> if(usr.Dive)
>

As Dive is 1 it will be true and it will work in the same way.

Now to your problem, As the user is moving to the next Z level, there is no need to move, you could simply edit the loc like so:

> usr.loc = locate(usr.x,usr.y,usr.z+1)
>

I think it takes time as you're moving to a different Z level, either that or you are doing extra processing at mob/Move().

Thx usr.loc = locate(usr.x,usr.y,usr.z+1) works like a charm