ID:865551
 
(See the best response by Kaiochao.)
Code:
            if(src.bot)
if(src.Health<=0)
flick('SB.dmi',src)
sleep(9)
var/obj/corpse/robot/a = new /obj/corpse/robot
a.loc = src.loc
del(src)
..()


Problem description:
I have this bot NPC, when its killed id like the broken pieces to fall down under it... But it doesn't seem to be doing that ;/

And here's the corpse:
obj
corpse
robot
icon = 'ICONS/NPCS/Robot1.dmi'
icon_state = "broken"
density = 0
New()
var/loc = src.loc
sleep(200)
if(src.loc == loc)
del(src)
..()
else
..()


Best response
When you create an object, its New() proc is called in the same line as the 'new' keyword. Because of the sleep() in the corpse object's New(), nothing after the 'new' line is happening while it still exists.
A couple things you can change to fix this issue:
  1. Initialize the corpse object at a location instead of setting its location after creation.
    //  e.g: Creating an object at a specific location
    var obj/o = new (loc)
  2. Use spawn() for your New() action. This creates a delay that doesn't interrupt anything else.
    New()
    ..()
    var initial_loc = loc
    spawn(200)
    if(loc == initial_loc)
    del src
Thank you once again!