ID:145631
 
Code: Simple code allowing me to clean up a blood spill.
//Obj is meant to be here...
Blood
icon = 'Effects.dmi'
icon_state = "Blood"
var/obj/B = /obj/Blood
Click(B)
if(get_dist(B,usr) == 0)
del(B)
view() << "[usr] cleans the blood pile."


Problem description: I clearly tell the Blood to delete itself when I click on it (and being over it too) but it deletes the turf BELOW it. Should I turn the blood into a turf/ etc., or keep it as a obj and rework the code?


Fixed, check Lummox's post if you want the holy code.
What is the purpose of B? If you are already clicking the obj, you should be able to delete it by saying del(src). Also, when checking to see something is 0, you can say if(!blah).
In response to Kija
The purpose of B is to take the place of src, which didn't work either.
Well, there are many many problems with that piece of code.

For one thing, the B var you've defined is outside the proc, so it bears no relationship to the argument B which is a different var. In this case, B and src.B mean two different things because you have a name conflict. src.B, the obj/Blood var, is set to a type path and not very useful to you. The argument B, on the other hand, is not what you think it is.

When atom/Click() is called, the argument passed to it is either the turf where it resides, or a text string representing a statpanel name where it was clicked. Because you're trying to del(B), you're deleting the turf that src is sitting on, not src itself.

Ergo, this is the correct code:
obj/Blood
icon = 'Effects.dmi'
icon_state = "Blood"
Click()
if(usr.loc == loc)
view() << "[usr] cleans the blood pile."
del(src)

Lummox JR
In response to Lummox JR
Couldn't see any faults at the time, now I see it a little. Thanks for the code, finally I am getting near to finishing a FULL project.
In response to RedlineM203
One thing I didn't point out was that if you want to be sure an argument matches a specific type path, just giving it that path isn't enough. You have to make sure it's actually that same type. For example, you can define Bump(mob/M), but M could still really be an obj or turf if that's what you bumped into. The type path in this case only tells DM that you expect M to be a mob, so when you use the . operator it should assume any use of mob vars/procs for M is correct.

Lummox JR