ID:149072
 
I cant get my punch verb to wait until a first punch is finished until you can make another, heres my code:

obj
punch
icon = 'punch.dmi'
density = 1
layer = 9
var
Str
Bump(mob/M)
if(istype(M,/mob))
M.HP-=src.Str
M.Deathcheck()
mob/verb/Punch()
if(usr.PW == 0)
usr.PW = 1
new/obj/punch(usr.loc)
for(var/obj/punch/P in usr.loc)
P.dir = usr.dir
P.Str = usr.PL/4
walk(P,usr.dir,3)
spawn(5)
del(P)
usr.PW = 0
if(usr.PW == 1)
usr<<"You are already punching."

PW is my Punch wait var, i set it to one so you cant attack again, then set it back to 0 when the punch is complete but it wont wait, the if(usr.PW == 1) message never comes, could someone help me with this?
everything after spawn() has to be indented for it to be included. Maybe you want sleep() instead. Sleep() doesn't need the next lines to be indented, spawn() does.
In response to Garthor
Thank you, ill try this.
Jotdaniel wrote:
I cant get my punch verb to wait until a first punch is finished until you can make another, heres my code:

obj
punch
icon = 'punch.dmi'
density = 1
layer = 9
var
Str
Bump(mob/M)
if(istype(M,/mob))
M.HP-=src.Str
M.Deathcheck()
mob/verb/Punch()
if(usr.PW == 0)
usr.PW = 1
new/obj/punch(usr.loc)
for(var/obj/punch/P in usr.loc)
P.dir = usr.dir
P.Str = usr.PL/4
walk(P,usr.dir,3)
spawn(5)
del(P)
usr.PW = 0
if(usr.PW == 1)
usr<<"You are already punching."

PW is my Punch wait var, i set it to one so you cant attack again, then set it back to 0 when the punch is complete but it wont wait, the if(usr.PW == 1) message never comes, could someone help me with this?

Also, you seem to be deleting P before setting PW to 0. Plus, just a tip, you don't need to check if usr.PW == 1 is you check, you can put else. Else is guaranteed to work properly unless there is more than one "else" statement in the proc/verb. It won't affect performance, but it'll make the code more compact.