ID:145507
 
I got a serious bug... I am PISSED!!!!! I asked this here about 3times, this time I hope at least 1 of u will help me...

Theres a verb called Magic Ball, which releases an object... when it bump, it check if ismob and if it does, it lower hes hp and stuff... all works great, then I added this lines of code so ppl wont pk in towns

turf/safe
safeblank
icon = 'blank.dmi'
Entered()
if(!(usr.monster))
usr.safe = 1
Exited()
if(!(usr.monster))
usr.safe = 0


Since then, everytime the ball bump the icon instead the person, and tells me usr is nothing, so entered and exited is bugged... so I changed it to

turf/safe
safeblank
icon = 'blank.dmi'
Entered()
if(istype(usr,/mob))
if(!(usr.monster))
usr.safe = 1
Exited()
if(istype(usr,/mob))
if(!(usr.monster))
usr.safe = 0


Now it just does nothing... the bug, I think is that the ball bump the icon, and hes not user, mob so he just stop it... how can I change it, so the ball will bump gd user instead? cheers.

You need to pass an argument. Ex; Entered(atom/movable/a)
The problem here is that you're using usr in procs... Enter(), Entered(), Exit(), and Exited() should never have usr in them...

Luckily, they all have a built-in argument that refers to the thing that triggered them...

So, you can do the following:

Entered(mob/M)
if(!M.monster)
M.safe = 1

And the same goes for the other ones...

And for safe coding, the basic rule is to simply never use usr, unless it is absolutely necessary... And in fact, there's really only two normal cases where it's necessary; Click(), and DblClick()... Usr should not appear anywhere else in your code...
In response to Mysame
First of all, hiya Mysame, didnt see u for a while...


Second, U OWN!! IT FINALLY WORKS, I LOVE U!!!!
In response to Souloron
Super, of course, when it's not a mob that's entered, it'll result in a runtime, thus;
turf/blabla/Entered(mob/M)
if(istype(M)) // If it is a mob
..() // Do whatever you want to do
In response to Mysame
You mean ismob() right? istype() expects 2 arguements. Also, you shouldn't be using ..() as a way to show "do whatever you want to do" because ..() just doesn't belong there unless /turf has a Entered() proc which was changed from default.
In response to Kalzar
istype() doesn't expect 2 argument. Read the Reference about it :p
In response to Mysame
Well, generally, unless you've got objs that are moving around as well, Enter() (and all related) will only ever be called by mobs...

So, I just use the mob type as the argument...

Yes, I realize that in some cases, you might have moving objs, and you'd need to use the more universal atom/movable type, but this is a decision made based on the game (I suppose the argument for "robust code" could be brought up, but, meh)

In an RPG-type game (as this appears to be), it is unlikely that objs will be moving, and thus, using mob/M as the argument should be fine... Nothing other than a mob will ever trip Enter(), Entered(), etc...
In response to Mysame
Oh heh. Whoops. >.>