ID:147804
 
I'm trying to make this rocket(new game, hehe) delete a nine-square grid around the object that the rocket bumps.
obj/rocket
icon = 'tiles.dmi'
icon_state = "missile"
density = 1
Bump(obj/O)
for(var/obj/Q in block(locate(O.x-1,O.y+1,O.z),locate(O.x+1,O.y-1,O.z)))
del(Q) //This is line 963, as referred to in the runtime error.
del(O)
del(src)

It'll delete the object it bumps, but nothing around it.

runtime error: bad del
proc name: Bump (/obj/rocket/Bump)
source file: Vehicles.dm,963
usr: 0
src: the rocket (/obj/rocket)
call stack:
the rocket (/obj/rocket): Bump(Box (/obj/Box))
looks like improper indentation.
In response to Airjoe
Yeah, I realized that a while ago, but my PC crashed and I couldn't post on the forums till now. It doesn't give me runtime errors anymore, but it still won't delete the objects around it.
obj/missile
icon = 'tiles.dmi'
icon_state = "missile"
density = 1
Bump(obj/O)
for(var/obj/Q in block(locate(O.x-1,O.y+1,O.z),locate(O.x+1,O.y-1,O.z)))
if(Q == O) continue
del(Q)
del(O)
del(src)
In response to Enigmaster2002
You have coded in an exception for O, but don't you really mean to code in an exception for src? Deleting O won't end the proc, but the missile itself is an obj within that block and the proc dies the instant the missile is deleted.
In response to Hedgemistress
obj/missile
icon = 'tiles.dmi'
icon_state = "missile"
density = 1
Bump(obj/O)
for(var/obj/Q in block(locate(O.x-1,O.y-1,O.z),locate(O.x+1,O.y+1,O.z)))
if(Q == src) continue
del(Q)
del(src)

I read the helpfile a little more carefully, and it said that the first argument is the lower left corner and the second argument is the upper right corner. Originally, I was defining a very odd box. It also says that block() lists turfs in the area specified... so I guess that means it doesn't work on objects?
In response to Enigmaster2002
Enigmaster2002 wrote:
I read the helpfile a little more carefully, and it said that the first argument is the lower left corner and the second argument is the upper right corner. Originally, I was defining a very odd box.

Yeah, that block() behavior kind of sucks. I've never seen any reason it should be that way; two opposite corners ought to do no matter what order they're in.

Incidentally, I'd switch to get_step() instead of the complex locate() youv'e got there. It's a little cleaner. Don't forget you also have to account for map edges, too, where both the locate() and the get_step() would come up will null.

It also says that block() lists turfs in the area specified... so I guess that means it doesn't work on objects?

Yeah, I've run across this problem before. It's tempting to try to loop through objs in a block() but the result is a bug that's almost impossible to chase down. The problem is, block() doesn't work like view(), and we're so used to working with those other procs that we forget it doesn't work. Kudos for figuring this out so quickly on your own; it's not an easy catch.

To do this properly you have to loop through each turf in the block, then through each obj in the turf.

Lummox JR
Why not just use citrus?
In response to Garthor
I stumbled upon range and orange just a bit ago, but even using that causes some odd deletion patterns. I can't get it to delete every object within one square of it.
obj/missile
icon = 'tiles.dmi'
icon_state = "missile"
density = 1
Bump(obj/O)
for(var/obj/Q in range(1,O))
del(Q)
del(src)
In response to Enigmaster2002
Is it just me or is the whole forum going Haywire? Because someone else posted the same message about 6 times.
In response to Mrhat99au
I'm truly sorry, I clicked the post button a mess of times because it wasn't working. Probably wasted a mess of bandwidth doing that... -.-'
In response to Enigmaster2002
I said citrus, damnit! CITRUS!
In response to Enigmaster2002
You've got the same problem... src is STILL an obj within range(1,O)... when src is deleted by the for() loop, the proc is dead, meaning any objs which come in the list after it aren't deleted. You've already got it deleting src at the end, but the proc ends before that because src is already deleted. What you really need to do is add a check, like if (Q != src) del Q
In response to Enigmaster2002
Why are you blowing up things arround the object it hits, why not the things actually arround the missile? Just use "for(var/obj/PoorObject in orange(1)) del PoorObject"?

Here's what I would do:
// To replace your line:
for(var/obj/OB in orange(1)) spawn OB.Bombed(src,10)

// Seprate from above:
obj
var/HP=31
proc/Bombed(atom/movable/A,DMG)
if(!HP) return
HP-=DMG
if(HP<=0) del src

This simulates the object having Hit Points and taking so much damage untill it's destroyed.
In response to Yota
orange()'s "center" argument is usr by default, so you have to change it in this case.