ID:145254
 
Code:Damn Bump
obj/dude2/Bump()
Dudify()

mob/proc/Dudify(mob/dude/M)
usr.Dots += 1
del src
if(usr.Dots == 127)
usr << alert("LEVEL COMPLETE!")


Problem description: lets say i want an obj to delete itself and edit the stats of someone wen it was stood on by a certain mob, how would i go about tht, cos i just get either nothing happening, OK written on screen or 1000's of proc crashes

DarkBelthazor wrote:
Code:Damn Bump
> obj/dude2/Bump()
> Dudify()
>
> mob/proc/Dudify(mob/dude/M)
> usr.Dots += 1
> del src // !
> if(usr.Dots == 127)
> usr << alert("LEVEL COMPLETE!")
>

There's your culprit. First you delete src, and then you expect for src to still exist, as you want the proc to continue.

obj/dude2/Bump()
Dudify()

mob/proc/Dudify(mob/dude/M)
M.Dots++
src.loc=null
src.contents=null
if(M.Dots == 127)
alert(M,"LEVEL COMPLETE!")
if(src.client)del src

This will work much better. Instead of deleting src, simply set it's loc to null. You probably never knew this, but there's a built-in garbage collector. Afterwards, it will see that there's a mob sitting in a null location with no references to anything whatsoever, and it will delete it automatically.

I have no idea if src is a player, and if src is a player, it won't be automatically deleted because it's still being linked by the client. In that case, it'll get deleted as usual with del src, but only if there's a player attached to it.

Last, but not least.

Lummox Jr wrote:
No usr in proc. Ungh.

01000100011000010111010001100001
No put usr in proc. Ungh.

Lummox JR
In response to Android Data
firstly, i put usr in it as a final resort cos i was out of ideas, secondly wat u sent me adds to my list of failed attempts, but thx anyway
In response to DarkBelthazor
DarkBelthazor wrote:
firstly, i put usr in it as a final resort cos i was out of ideas, secondly wat u sent me adds to my list of failed attempts, but thx anyway

Well putting usr in the wrong place is never a good thing, especially if you're out of ideas. But if the code you saw didn't work, be specific and tell us how.

Lummox JR
In response to Lummox JR
true, but still, thx n e way
In response to DarkBelthazor
DarkBelthazor wrote:
true, but still, thx n e way

DarkBelthazor also wrote:
firstly, i put usr in it as a final resort cos i was out of ideas, secondly wat u sent me adds to my list of failed attempts, but thx anyway

"Your help is a failed attempt but thanks anyway." What kind of a response is that? True, the help did not fully solve all your problems, but you should not brush it off as worthless failure. I think that's rude, especially since people are taking the time to try and decipher your cryptic speech just so they can help you. If you're not going to make it any easier on people to try and help you, then they have not failed at anything when their help didn't solve all your problems.

Since I'm posting, I might as well give you some help as well (beyond the off-topic help I already gave).

Your runtime errors are probably stating "Cannot modify null.variable," aren't they? In your original attempt, M is going to be null since you aren't passing anything to it. That problem is the part Android Data seems to have overlooked, though he did solve half your problem.

(edit)
I also suspect you have your Bump belonging to the wrong object, if I understand what you're trying to accomplish. Bump belongs to the object that is doing the bumping, not the object that is being bumped. So you would want mob/Bump to call Dudify on the object, I suspect, and then delete the object being bumped.

After you do that, your src deletion problem can be easily fixed by setting src to null before deleting it. For example...
mob/Bump(atom/movable/M)
if(istype(M, /obj/dude2))
M.Dudify(src)
obj/dude2/Dudify(mob/M)
//do the stuff you need to do
var/obj/O = src
src = null
del(O)

Setting O to src then src to null allows you to "detach" the function from the source object so that the function won't die when you delete the object.
In response to Loduwijk
i meant 'I failed to encorporate the code into my source', so i failed, not them. Second thx for ure code advise, i am not 'brushing it off' as a failure like u said i was doing and finally, if u ask the ppl who know me, im the complete opposite of rude, so sry to everyone if i came across tht way.
In response to DarkBelthazor
DarkBelthazor wrote:
if u ask the ppl who know me, im the complete opposite of rude, so sry to everyone if i came across tht way.

Alright then, no harm done. I know how that is, as I've been accused of being angry and rude before when I certainly wasn't anything of the sort. That's why I take extra care to try and craft what I say into a way that cannot be mistaken for negative. It's an annoying hastle sometimes, but it has helped.