ID:175001
 
I was wondering if this : is a bad thing i use it a lot in procs like


obj/proc/Punch(N)
N:hp -= 10
if(N:hp <= 0)
N:Die(N)
mob/proc/Die(N)
ect.


If I dont use this : I get a error.

N.hp:undefined var

It seems to work just fine but I think it was Nadrew that said it was a newbie thing or somethin. I never have a problem with this operator.
The reference is a little cryptic on this subject, so I'll explain it here.

The . (dot/period) operator is by far the preferred one to use. You know what it does already, so I won't bother to explain.

The : (colon) operator is sometimes convenient to use, but it can cause runtime errors. Basically, it stops the compiler checking to make sure that the specified var/proc will always exist when applied to the var before the colon. For example:

<code>obj/stuffandnonsense var/hello=1 mob/verb/test() var/obj/O=new O.hello=0</code>

This will cause a compiler error, because base objs don't have the "hello" var; only obj/stuffandnonsense objs have it. Changing the last line to use a colon, like so...

<code>obj/stuffandnonsense var/hello=1 mob/verb/test() var/obj/O=new O:hello=0</code>

...will get rid of the compiler error. But it will produce a runtime error when you use the test verb, because even though there's no compiler error that doesn't mean it's right.

In other words, the colon operator tells the compiler to ignore mistakes that could turn up runtime errors. This is bad, because it's still a problem anyway and runtime errors are harder to detect and debug than compiler errors.

In your example, simply declaring the N var as a mob would remove the need for the colon:

<code>obj/proc/Punch(mob/N) N.hp -= 10 if(N.hp <= 0) N.Die(N)</code>
In response to Crispy
Thanks Crispy as always.