ID:140779
 

mob
proc
Deathcheck(mob/M)
if(usr.hp<=0)
hp=0
if(usr.Bendingability=="Eart")
usr<<"You have been killed by [M]"
usr.hp=usr.Mhp
usr.Death+=1
M<<"You have killed [M]"
M.kills+=1
usr.loc=locate(16,64,1)
if(usr.Bendingability=="Water")
usr<<"You have been killed by [M]"
usr.hp=usr.Mhp
usr.Death+=1
M<<"You have killed [M]"
M.kills+=1
usr.loc=locate(20,56,1)
if(usr.Bendingability=="Fire")
usr<<"You have been killed by [M]"
usr.hp=usr.Mhp
usr.Death+=1
M<<"You have killed [M]"
M.kills+=1
usr.loc=locate(11,56,1)
if(usr.Bendingability=="Wind")
usr<<"You have been killed by [M]"
usr.hp=usr.Mhp
usr.Death+=1
M<<"You have killed [M]"
M.kills+=1
usr.loc=locate(20,64,1)


runtime error: Cannot read null.kills
proc name: Deathcheck (/mob/proc/Deathcheck)
usr: the hgghgh (/mob)
src: the hgghgh (/mob)
call stack:
the hgghgh (/mob): Deathcheck(null)
the hgghgh (/mob): kill(the hgghgh (/mob))
You have been killed by :



could someone plz help me with this, with help i mean with what i did wrong with this code so i wont make the same mistake again


thx for taking the time to read this
You're calling your proc wrong. M is null.

Put in a parameter when you call your proc.
There are a lot of mistakes here and some are severe.

I would guess that you are not passing a mob as argument to the procedure as expected, judging from the runtime error.
You are abusing usr in a procedure, which can cause a lot of trouble.

Your multiple if checks should really be a switch and you should not copy and paste part of the source code multiple times.
As only the location differs, the rest does not have to be included within the if clause.

I won't even mention the bad design decisions and the lack of object-oriented programming, including inheritance and modularity.

Edit:
Gah, I take too long trying to look up various links and compiling a half detailed response, so naturally somebody posts before me :/
In response to Schnitzelnagler
well i am not good in procs


maybe someone could show me a demo ???
In response to Chico1
mob
proc
Deathcheck()
if(src.hp <= 0)
hp = 0
switch(src.Bendingability)
if(src.Bendingablility == "Earth")
src <<"You have been killed by [M]"
src.hp= src.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(16,64,1)
if(src.Bendingability == "Water")
src <<"You have been killed by [M]"
src.hp = usr.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(20,56,1)
if(src.Bendingability == "Fire")
src << "You have been killed by [M]"
src.hp = src.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(11,56,1)
if(src.Bendingability=="Wind")
src <<"You have been killed by [M]"
src.hp = src.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(20,64,1)


I believe this should work, im no expert though, you can find alot of demo's on the resources page, just search for deathcheck or death. and you should be able to find something.
In response to Zeppo
thx for helping me
In response to Chico1
still not fixed
In response to Chico1
how are you calling the proc?


and try this:
mob
proc
Deathcheck()
if(src.hp <= 0)
src.hp = 0
if(src.Bendingablility == "Earth")
src <<"You have been killed by [M]"
src.hp= src.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(16,64,1)
if(src.Bendingability == "Water")
src <<"You have been killed by [M]"
src.hp = usr.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(20,56,1)
if(src.Bendingability == "Fire")
src << "You have been killed by [M]"
src.hp = src.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(11,56,1)
if(src.Bendingability=="Wind")
src <<"You have been killed by [M]"
src.hp = src.Mhp
src.Death += 1
M << "You have killed [M]"
M.kills += 1
src.loc = locate(20,64,1)

In response to Zeppo
if i do it without the mob/M he is not getting the M and gives errors



death.dm:7:error:M:undefined var
death.dm:10:error:M:undefined var
death.dm:10:error:M:undefined var
death.dm:11:error:M.kills:undefined var
death.dm:14:error:M:undefined var
death.dm:17:error:M:undefined var
death.dm:17:error:M:undefined var
death.dm:18:error:M.kills:undefined var
death.dm:21:error:M:undefined var
death.dm:24:error:M:undefined var
death.dm:24:error:M:undefined var
death.dm:25:error:M.kills:undefined var
death.dm:28:error:M:undefined var
death.dm:31:error:M:undefined var
death.dm:31:error:M:undefined var
death.dm:32:error:M.kills:undefined var
In response to Chico1
Think about it, it makes sense - if you do not define who M is, how can you modify its values?
if(M)   //  Is M is NOT 0, "", null
M.kills += X
M.Y = Z
In response to GhostAnime
i am totoly confused now i search for demo's but all the demo is the basic death proc for just the player there is no demo (or i did not found it) that shows how you can do it with difirent class,race
In response to Chico1
could someone plz make a demo for me with the death proc for more then 1 class or race??
In response to Chico1
your problem could be solved the easy way by taking the "chatter" out of the deathcheck proc. and rather have it somewhere else.

it might be rather bad coding, but having it under the attack verb, as an example. or someplace else might be a solution.


mob
verb
attack(mob/M as mob in world)
M.hp -= src.strength
src << "You attack [M]"
M << "[src] attacks you!"
if(M.hp <= 0)
M.deathcheck() // now without mob/M and without any M in the proc.
sleep(2)// just set a delay (might really not be nessecary.
M << "You where killed by [src]"
src << "You killed [M]"


shouldn't this fix the problem? its probably really bad but i think it might work. now just remove all the M. stuff from the original deathcheck. ;)
In response to Zeppo
Ignore Zeppo as he appears to not know enough to try to help you.

mob/verb/attack()
var/mob/m in get_step(src,src.dir) //find a mob your facing
if(m) //if we found it
m.takedamage(9001)
//or however your dealing with damage
m.deathcheck(src)
//Whenever deathcheck() is called, do it like that
mob/proc/deathcheck(mob/killer)
if(src.hp<=0) //if your hp is
if(src.client)
src.loc=locate(x,y,z) //or any respawn points, whatever
//point is don't delete it if it's a player
else //it's an npc
//do stuff
del(src) //get rid of it
world<<"[src] died because [killer] commited a murder!"
//announce it's death
In response to Chico1
I'd recommend reading the guide and brushing up on procs. You won't go far if you only learn from demos.
In response to Vic Rattlehead
well who might you be ?

1. what i said works. might get rid of the delay but other than that it works.

2. theres more than one solution in this world.

3. if you are refering to how i set things up in my example, it was just that, an EXAMPLE.

last but not least. have fun ;)
In response to Zeppo
No, it's buggy and barely functional. Examples shouldn't have poor programming practices.
In response to Zeppo
What you said [b]doesn't[/b] work. You need to pass a parameter to deathcheck. This parameter needs to be the thing that the player killed.
In response to Vic Rattlehead
whatever..

either way, 98% of those who can help without poor programming are not capable of helping, they simply refuse to help.

the closest to helping most of them come are "read the DM guide" or "F1 and look up ..." now this is all good, but what if the person does not understand it.. somethings in the guide i myself need to read twice or even "trice" funny word i made up now. YES IT'S MINE!!. before i understand it in a way that makes me able to use it properly. "GOOD READ IT A MILLION TIMES" you might say or till you get it. but really helping by showing how its done and using proper explaining is a good way to help one, this means, that they learn something new + they get the problem solved.

and all this because "you only want others do make the game for you" thats the reason, they think that every soul on byond that asks for help on byond wants someone else to make their game for them. thus they do not bother, they might even go so far as to come with hits and hunches.

BAD BAD you GOOD programmers of byond.

- The best way of learning is teaching. FACT

EDIT: BTW we're way of topic now.
In response to Zeppo
Zeppo wrote:
either way, 98% of those who can help without poor programming are not capable of helping, they simply refuse to help.

This depends on how you define help.
If by help you refer to throwing a code snippet to some for them to copy and paste it, you are right, I hope that nobody does this.
This is far from helpful on the long run.


Zeppo wrote:
somethings in the guide i myself need to read twice or even "trice"

If you have to read a context thrice (which us by no means a new word) in order to comprehend, then read it thrice.
After this little effort, you are capable of doing things without requiring the help of others, which seems far better than having to come back over and over again begging for somebody to create 'your' game.


Zeppo wrote:
but really helping by showing how its done and using proper explaining is a good way to help one, this means, that they learn something new + they get the problem solved.

Which unfortunately is not the case.
I could have replied to the original poster with a proper solution for the specific problem at hand (had the OP provided all relevant information, that is). But to what benefit?
Experience on the forum shows that people rather copy and paste, then head on without learning. And even if they are willing to learn, how does the OP realise when to use 'usr' and when to use 'src', unless you provide material with decent information on the issue?
What a code snippet teaches is but one single use of a given interface structure.
What reading the reference teaches is all the various possibilities the language provides.

Using examples to ensure that you know something is smart.
Using examples to learn something provides you with very limited experience.
Page: 1 2