ID:142246
 
Code:
mob
var
movedelay = 0.01
movestop = 0
Move()
if(dir == SOUTHWEST)
return
if(dir == NORTHWEST)
return
if(dir == NORTHEAST)
return
if(dir == SOUTHEAST)
return
else
if(movestop)
return 0
movestop = 1
..()
sleep(movedelay)
movestop = 0


Problem description:
The mob can move fine, but when the directional button is held down the mob moves very fast
It is desired for the proc to respond very quickly, but to stop the super fast movement that is the result of holding the key down
Examples

E.G.1
The player moves left and quickly press up
It moves left and right after it goes into the next tile it starts to move up

E.G.2
The player presses the right button and holds it.
The mob moves into the next space and then moves into the right space as planned, but it waits to stop moving (very short time, less than 1/10 of a second so it looks as if the mob icon doesnt stop moving) and stops moving after they release the button

(Ill try to make a video of this to make it more clear :P)
I had this working in 3.5 but its not working in 4.0
mob
var
movedelay = 0.01
movestop = 0
Move()
if(dir == SOUTHWEST)
return
if(dir == NORTHWEST)
return
if(dir == NORTHEAST)
return
if(dir == SOUTHEAST)
return
else
if(movestop) return 0
else
movestop = 1
spawn(movedelay) movestop = 0
..()


Try that.
client/Move() should be used to block player movement, not mob/Move(), and use the dir argument rather than the object var. Also, your override should still return the original return value (just calling ..() without storing or using what it returns loses that value) back, as well as not use sleep() (use spawn() instead if needed) so the caller isn't delayed.
sleep() can only use integer values.

[Edit]
Here is a way I have it in my beginner's demo/tutorial that I'm working on. It refers to other things in the demo that I've not provided here, so you can't just copy it and expect it to work, but it does demonstrate how to do it.
In response to Andre-g1
Andre-g1 wrote:
> mob
> var
> movedelay = 0.01
> movestop = 0
> Move()
> if(dir == SOUTHWEST)
> return
> if(dir == NORTHWEST)
> return
> if(dir == NORTHEAST)
> return
> if(dir == SOUTHEAST)
> return
> else
> if(movestop) return 0
> else
> movestop = 1
> spawn(movedelay) movestop = 0
> ..()
>

Try that.

This does the same thing, when the key is held down the mob moves once, then slight lag, then super quick move with no lag

Kaioken wrote:
client/Move() should be used to block player movement, not mob/Move(), and use the dir argument rather than the object var. Also, your override should still return the original return value (just calling ..() without storing or using what it returns loses that value) back, as well as not use sleep() (use spawn() instead if needed) so the caller isn't delayed.

I wanted to be able to block movement from all mobs, not just the client

I never thought of using spawn for this though

Clarification: I'm trying to make it so the mob goes the same speed regardless of the key being pressed a few times or being held down, and i don't want to make the mob show a stop at every tile.
Example of the stop:

Buttons Pressed: ->->->->^^
Movement: ->->->->(1 Sec LAG)^^
In response to KingCold999
mob
var
movedelay = 0.01
movestop = 0
Move()
if(dir == SOUTHWEST||dir == SOUTHEAST||dir == NORTHWEST||dir == NORTHEAST||movestop)
return 0
else
movestop = 1
spawn(movedelay)
movestop = 0
..()


Tested it, I believe that's what you want, if not I must have misread something.
In response to Andre-g1
Thansk, im not having any problems with moving now except when the person holds down the button

Sequence of events:

press and hold ->

What happens:

->(lag)->->->->->->->
^^^
Is there any way to get rid of the lag, so there is constant movement instead of "step, then run!!!"?
In response to KingCold999
I think that has to do with how byond handles movement, seeing as I see that happen in -most- if not -all- games.
In response to Andre-g1
I had the no-lag with a move code i used in byond before, I lost the source for my old project though (maybe it was from 3.5 and isn't in 4.0)
In response to Andre-g1
dir == SOUTHWEST||dir == SOUTHEAST||dir == NORTHWEST||dir == NORTHEAST
//can be summarized as
(dir&(dir-1))
//in this case
In response to KingCold999
KingCold999 wrote:
I wanted to be able to block movement from all mobs, not just the client

Overriding client/Move() will still apply for all mobs when a player initiates movement, and is what should be used here.

It is quite bad to block all mobs' movement with mob/Move(), because that will simply basically break your other code that may cause and expect mobs to move, and it's pointless because all non-directly-player-initiated movement is completely up to you, so the better course of action would be to simply make your code properly: so instead of telling mobs to move then blocking them if they are not supposed to, just don't tell them to move if they're not supposed to, in the first place.