ID:171483
 
Thanks to DeathAwaitsU for helping me fix a prob!
---------------------------------------------------------

on another matter,

is this wrong? and what could I do instead?

Thanks in advance.

mob/proc
KO_Check()
if(src.HP <= 5)//checks if the users HP is 5 or less
src.ko = 1
view() << "<B>[src] is knocked out!</B>"
DeathCheck()
if(src.dead == 1)
world << "<B>[src] has been killed by [usr]</B>"
src.HP = 5
src.loc = locate(60,50,1)
Farkas wrote:
is this wrong? and what could I do instead?

Yes, the code you posted is wrong.

mob/proc
KO_Check()
if(src.HP <= 5)//checks if the users HP is 5 or less
src.ko = 1
view() << "<B>[src] is knocked out!</B>"


Problem here: view() implies usr as its point of reference. Use view(src) instead.

    DeathCheck()
if(src.dead == 1)
world << "<B>[src] has been killed by [usr]</B>"
src.HP = 5
src.loc = locate(60,50,1)


Here, you should have sent an argument to DeathCheck() telling it who killed src, instead of relying on usr at all. The rule of thumb is: Never put usr in a proc. (You also shouldn't use ==1 and ==0 for yes/no tests on your vars. if(thevar) and if(!thevar) are better.)

DeathCheck(mob/killer)
if(HP <= 0)
world << "<B>[src] has been killed by [killer]</B>"
HP = 5
loc = locate(60,50,1)


Lummox JR
In response to Lummox JR
ok, thanks for the reply.

I have done exactly as you have written, except with the
if(dead == 1)

is this bad? will it cause problems? because it is the only way that this will work the way i want it to.

Farkas
In response to Farkas
Farkas wrote:
ok, thanks for the reply.

I have done exactly as you have written, except with the
if(dead == 1)

is this bad? will it cause problems? because it is the only way that this will work the way i want it to.

Farkas

He is telling you that if(dead == 1) is the same as if(dead). If you are checking boolean(true or false) 1 is ture and 0 is false. Therefore you don't need ==1 or ==0. instead use if(dead) or if(!dead) respectively.
In response to Jik
ahh, i see, thanks for clearing that up.

Farkas
In response to Jik
Jik wrote:
He is telling you that if(dead == 1) is the same as if(dead).

Actually it's not quite the same, which is why ==1 is a problem. If dead becomes any other value, this is no longer true, even though it's obviously meant to be a simple true/false test. Likewise var==0 should be replaced with !var because !var checks against things like null and "" besides just 0.

Lummox JR
In response to Lummox JR
Lummox JR wrote:

Actually it's not quite the same, which is why ==1 is a problem. If dead becomes any other value, this is no longer true, even though it's obviously meant to be a simple true/false test. Likewise var==0 should be replaced with !var because !var checks against things like null and "" besides just 0.

Lummox JR

i have took your advice lummox jr, i have done if(dead) and if(!dead)

Thanks for the help guys,

Farkas