ID:150925
 
I want to make it so when the player hits the attack verb, the player attacks, sleep(5), then the player keeps attacking untill the monster is dead, or the player dies. I also want to make a calm() verb so the player can stop attacking when he/she presses it.



mob
verb/attack(mob/M as mob in oview(1))
if (M.dead == 0)
if (M.HP >= 0)
flick("malefight",src)
usr << "You attack [M]!"
oview() << "[usr] attacks [M]!"
var/damage = rand(strength)
usr << "[damage] damage!"
M.HP -= damage
M.DeathCheck()

I tried this, but it doen't seem to work. It comes up with an error that says: Cannot read null.dead , then it stops attacking


mob
verb/attack(mob/M as mob in oview(1))
if (M.dead == 0)
if (M.HP >= 0)
flick("malefight",src)
usr << "You attack [M]!"
oview() << "[usr] attacks [M]!"
var/damage = rand(strength)
usr << "[damage] damage!"
M.HP -= damage
M.DeathCheck()
attack() //right here I try to make the loop



In this example, basicly he just attacks once with success, but when it tries to loop, it just says an error.

Your attack verb needs to know what it is attacking (that's the M var you have in there). Problem is, the second time you call it in a loop, you don't give it anything. That's why you got the can't read null.dead message. So, when you call it again, you need to pass in M as the argument.

Also, I'd advise looking into spawn() to take care of your sleeping in between attacks - it will not only wait like you want it to, but it will avoid any possible infinite loops. See the reference for more info...

<font size="-2">how was that, Lexy?</font>
In response to Air Mapster (#1)
Ok, now I've made it so when youatack, he keeps attacking, and when you die he stops attacking, and when you pull away from the enemy, he stops attacking. But now I need a calm verb so if they say for example are cornered and you are accidently attacking a friend, you can just click the calm verb and stop attacking.