ID:143846
 
Code:
client
East()
if(usr.canmove == 0)
return
return 1
West()
if(usr.canmove == 0)
return
return 1
North()
if(usr.canmove == 0)
return
return 1
South()
if(usr.canmove == 0)
return
return 1
Northeast()
return
Southwest()
return
Northwest()
return
Southeast()
return


Problem description:
The mobs can't move, even when usr.canmove = 1
What am I doing wrong?


You need ..() in there somewhere to call the default action, which in this case would be to move the mob.

The way you have it, attempting to move in a direction returns either 1 or 0... it never actually moves anything.

Basically what you want is something like this:

client
Move()
if(!src.canmove)
return
..()


Now isn't that a lot simpler?


Additionally, you want to avoid using 'usr' 99.9993% of the time, unless its in object verbs or Click() calls, in which case there's no other way to refer to the person who did it. But typically, you ALWAYS, ALWAYS, ALWAYS want to use 'src' to refer to the source object, the owner of the function you're working with. Avoid using 'usr' at all costs if you can help it.

And furthermore, if a value is a boolean value (that means 0 = false and 1 = true), then use if(value) to check if its true, and if(!value) to check if its false. Your code will be much more error-resistant that way.
In response to Foomer
Or, to elaborate more, 0, "", and null are false, and everything else is true.
In response to Foomer
Even when i put src.canmove = 0, the player can't move.

Oh and it gave me an error, undefined variable so i changed it to src.mob.canmove = 0
In response to RuneKingOmega
that is because you need 2 equal to signs not one, so src.canmove == 0 should work
In response to Foomer
What I would say, though i normally do,
else
...()

I'll have to update my stylings.
In response to Darkdemonrad
They are functionally equivalent, except with the possibility of one extra line of binary code using the else statement (and your typo).
In response to RuneKingOmega
I'd suggest handling the "canmove" stuff solely through the client, not the mob. Client movement is "voluntary" movement, and mob movement isn't always. It's silly to not get moved through a teleporter because you've made a move yourself within the last couple ticks.
In response to Garthor
nvm i fixed it. Didn't even need the else
client
Move()
if(src.mob.canmove == 1)
return ..()
Northeast()
return
Southwest()
return
Northwest()
return
Southeast()
return
In response to RuneKingOmega
RuneKingOmega wrote:
nvm i fixed it. Didn't even need the else
> client
> Move()
> if(src.mob.canmove == 1)
> return ..()



Good call, but you're still ignoring what I said about boolean values. Your code should never say "== 1" or "== 0" for a value that's either TRUE or FALSE. It should be written like this:

client
Move()
if(src.mob.canmove)
return ..()


Its a very good habit to get into.
In response to Foomer
A perfect example for why not to use ==1 or ==0 is just for the fact of, what if canmove suddenly equals 2?

For those variables, it's best to just flip them, instead of changing them.