I've been running in a lot of problems latelly so whenever I need help I will post in this topic. I'm having trouble with my battle system.
this error keeps popping up whenver I attack even when attacking nothing which shouldn't happen.
runtime error: Cannot read null.name
proc name: Damage (/mob/proc/Damage)
usr: Codesterz (/mob)
src: Codesterz (/mob)
call stack:
Codesterz (/mob): Damage(null, 8, null)
Codesterz (/mob): A()
I'm pretty sure the bug is in this part of the attack code.
mob/proc/Damage(var/Damage, var/Hit, mob/monster/M)
if(usr.Strength == usr.Strength)
Hit = rand(1,usr.HitChance)
if(Hit <= 2)
if(usr.Strength > M.Defense / 2)
Damage = usr.Strength - M.Defense / 2
Damage = rand(1,Damage)
src.HP -= Damage
usr << "You attack [M.name] for [Damage] Damage!"
usr.AttackWait()
M.DeathCheck()
return
else
Damage = rand(1,2)
usr.AttackWait()
M.DeathCheck()
return
else
usr << "You swing at [M.name], but miss!"
usr.AttackWait()
return
ID:147830
Nov 7 2003, 4:44 pm
|
|
In response to Jon88
|
|
I tried to edit my Attack verb and now the guy won't even attack the monster. Here's the attack verb and yes I do realize how crappy it is, but it is good enough for now.
mob/verb/A() set hidden = 1 var/mob/M for(M in get_step(src,src.dir)) break if(M) if(usr.Attacking == 0) usr.Attacking = 1 usr.HitChance = 10 if(usr.Accuracy >= M.Agility) usr.HitChance -= 2 if(usr.Accuracy >= M.Agility + 1) usr.HitChance -= 2 if(usr.Accuracy >= M.Agility + 2) usr.HitChance -= 1 if(usr.Accuracy >= M.Agility + 3) usr.HitChance -= 1 if(usr.Accuracy >= M.Agility + 5) usr.HitChance -= 1 if(usr.Accuracy >= M.Agility + 10) usr.HitChance -= 1 if(usr.Accuracy >= M.Agility + 15) usr.HitChance -= 1 if(usr.Accuracy >= M.Agility + 25) usr.HitChance -= 1 usr.Damage() return else usr.Damage() return else usr.Damage() return else usr.Damage() return else usr.Damage() return else usr.Damage() return else usr.Damage() return else usr.Damage() return else usr.HitChance -= 1 usr.Damage() return else return |
The bug is in the call to the Damage() proc as someone else said. You'll want to add a null check before Damage() is called (In A() I belive).
Also, you should be using src instead of usr. I don't see it having any effect here, but it's a bad idea to use usr all the time (It's a bad habit). |
In response to DarkView
|
|
I know I shouldn't use usr and I rarelly do use it but When I was working on this code I was pretty damn tired when I'm not so lazy I'll change it.
|
In response to Codesterz
|
|
I take it the mistake must be something really simple or hard. Could I ask why no one will help me out. On have my posts that I ask for help on no one answers. DO you guys have something against me??? Well anyways please help I'm kind of at a pause in the game until someone can help me.
|
Looking at your error, you can see that
is what is being called. Something is passing null values to your Damage() proc when it gets called.