ID:141725
 
Code:bump code
  Bump(atom/P)
if(ismob(P))
var/mob/pig=P
view(P)<<"[pig] was hit by an [src]!"
pig.health-=75
P:deathcheck()


Problem description:it compiles but when i hit some1 with the deathcheck i get an error saying it cannot run the death check wat as i suppose 2 do

Try this:
  Bump(atom/P)
var/mob/pig/D
if(istype(P. /mob/pig/))
view(P)<<"[D] was hit by an [src]!"
D:health-=75
D:deathcheck()
In response to Daniel1322da
Never (ab)use the : operator. Typecasting is the safest way.

Example:
obj
fish
var/stinky=1
Click()
if(istype(src,/obj/fish))
var/obj/fish/f=src //typecasting
if(f.stinky)usr<<"The [src] is stinky!" //[src] or [f], both work in this situation.
else usr<<"The [src] is not stinky."

Of course, in this example, typecasting isn't needed at all since Click() could simply be defined under /obj/fish, but hopefully you get the point.
In response to Kaiochao
but hes trying to do Bump()
Not Click()
And in same cases you have to use the :, but this time i didnt know why i put in :, nor do i know why he PUT it in.
I only use it in the cases where my code wont work otherwise.
In response to Daniel1322da
That was an example. Apparently you didn't get the point.
Typecasting makes it so you don't need to use the : operator. You really 99.9% never need to use the : operator.
In response to Kaiochao
I will have to look at typecasting then.
Thankyou :)
In response to Daniel1322da
when i use urs it says the 3rd line is missing expression
I don't actually see anything wrong, try posting your deathcheck() proc here (i think that's the actual problem).
First of all, : is bad. Always use . instead.

: will give runtime errors if the thing you are trying to access doesn't have the proc or var you're trying to use/change. . will give compiler errors instead for the above reasons.

P doesn't have the death check proc, so you're getting errors.
In response to Daniel1322da
And in same cases you have to use the :

You type cast instead, like KaioChao said. : is never needed, ever.

mob/var/v1
mob/New_Type/var/b1

mob/Bump(atom/A)
if(ismob(A))
var/mob/M = A //typecast M and set it to A
world << M.V1 //there is no V1 var (the compiler is case sensitive)
//so you will get an error when compiling, therefore
//your players won't ever see this bug

obj/Bump(atom/A)
if(ismob(A))
world << A:b1 //you will get runtime errors because
//mobs don't have a b1 var. This could
//easily be a typo or something. Your players
//WILL see this, and it gives an unprofessional feel
//to your game


Fix'd

I guess I should have used multi line comments, oh well.
In response to Jeff8500
In this case the compiler will still be able to catch the error, as there is no var ever called 'b1'. The : operator will fail checking that specific type having the var though, so if you're trying to use a var name that exists but on the wrong object type, it will still compile.
In response to Kaioken
so in my code if i change : to . it should work?
In response to Mel23jones
No, because your mob still won't have a death check proc.
In response to Jeff8500
can some1 help me rewrite the original code 2 if some1 were hit by it they lose 75 health and run a deathcheck
In response to Mel23jones
Sorry, but you're a Help Vampire and has been one for a while now. We are not here to program your code for you. Care to actually learn the language yourself first, before asking for help? Or if you're looking for someone else to program for you, hire or get a programmer.