ID:166167
 
I have started creating an RPG, and I have begun to create a battle system. However, although killing enemies seems to work fine, every time an enemy is destroyed I recieve the following error:

runtime error: Cannot read null.HP
proc name: attack (/mob/verb/attack)
usr: RoadToDawn (/mob)
src: RoadToDawn (/mob)
call stack:
RoadToDawn (/mob): attack(null)

Do you know how to fix this?

My battle system looks like this:

    verb
say(msg as text) //what the usr says is passed into "msg" as text
world << "[usr]: [msg]" //the world sees chatroom-like output
attack(mob/M as mob in oview(1)) //attack a mob within 1 tile of you
usr << "You attack [M]!" //send this message to the usr
var/damage = rand(1,10)+Strength //assign a random # to a new variable and add strength
usr << "[damage] damage!" //tell the damage to the usr
M.HP -= damage //take away the damage from M
M.DeathCheck(src) //check for death with a proc
if (M.HP>=0)
usr << "[M] attacks you!"
var/Mdamage = rand(1,10)+M.Strength
usr << "You lose [Mdamage] HP!"
usr.HP -= Mdamage
else
..()


and my DeathCheck proc looks like this:

    proc
DeathCheck(mob/M) //checks to see if an attack is deadly
if (HP <= 0) //if the defender's HP is low enough...
M << "You killed [src]!" //do the death messaging
M.GainEXP(src.EXP)
del(src) //delete whatever just died



I cannot make out what the problem is, and its really frustrating.

Thanks
RoadToDawn wrote:
I have started creating an RPG, and I have begun to create a battle system. However, although killing enemies seems to work fine, every time an enemy is destroyed I recieve the following error:

runtime error: Cannot read null.HP
proc name: attack (/mob/verb/attack)
usr: RoadToDawn (/mob)
src: RoadToDawn (/mob)
call stack:
RoadToDawn (/mob): attack(null)

Do you know how to fix this?

Well the error gives the details as to what is happening. Your attack proc is being run even though there is no mob one tile away. Thus, attack(null) is being run. So it can't read null.HP(M.HP) if it had a mob reference.

As to fixing it. BWICKI! http://bwicki.byond.com/ByondBwicki.dmb?DeathCheck

My battle system looks like this:

>   verb
> say(msg as text) //what the usr says is passed into "msg" as text
> world << "[usr]: [msg]" //the world sees chatroom-like output
> attack(mob/M as mob in oview(1)) //attack a mob within 1 tile of you
> usr << "You attack [M]!" //send this message to the usr
> var/damage = rand(1,10)+Strength //assign a random # to a new variable and add strength
> usr << "[damage] damage!" //tell the damage to the usr
> M.HP -= damage //take away the damage from M
> M.DeathCheck(src) //check for death with a proc
> if (M.HP>=0)
> usr << "[M] attacks you!"
> var/Mdamage = rand(1,10)+M.Strength
> usr << "You lose [Mdamage] HP!"
> usr.HP -= Mdamage
> else
> ..()
>

and my DeathCheck proc looks like this:

    proc
> DeathCheck(mob/M) //checks to see if an attack is deadly
> if (HP <= 0) //if the defender's HP is low enough...
> M << "You killed [src]!" //do the death messaging
> M.GainEXP(src.EXP)
> del(src) //delete whatever just died
>

I cannot make out what the problem is, and its really frustrating.

Thanks