Simple Collisions

So i am writing a function that will destroy certain objects when the collide with this sensor. Im positive there is an easier way and i have overcomplicated it. But the point is, it doesnt work!

NOTE:

the sensor has the key = “key”
the other three objects have been assigned yes, yay, and die. I made these because if i gave them all the same one then it wouldn’t know what was actually colliding.

Oh, and why wont my removeSelf() work?

[blockcode]

local function winHere(w)

if(w.object1.key == “key”) and (w.object2.myName == “box”) then
w.object2:removeSelf();
if(w.object1.key == “key”) and (w.object2.myName == “triangle”) then
print(“2”)
w.object2:removeSelf();
if(w.object1.key == “key”) and (w.object2.myName == “circle”) then
print(“3”)
w.object2:removeSelf();
if(w.object1.myName == “box”) and (w.object2.key == “key”) then
print(“4”)
w.object1:removeSelf();
if (w.object1.myName == “triangle”)and (w.object2.key == “key”) then
print(“5”)
w.object1:removeSelf();
if (w.object1.myName == “circle”) and (w.object2.key == “key”) then
print(“6”)
w.object1:removeSelf();
end
end
end
end
end
end
end

[/blockcode] [import]uid: 59735 topic_id: 16791 reply_id: 316791[/import]

Did you try adding them up like in a binary number and checking for bits?

About your removeSelf() not working, the w is the event object, not the display object. The object that needs to be removed is either w.object1 or w.object2

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16791 reply_id: 62858[/import]

okay, thanks. It works how it should the first time, but once it has been destroyed and another one spawns, after the code (ive updated above) runs, I receive an error in the terminal saying that this object has been removed before? [import]uid: 59735 topic_id: 16791 reply_id: 62867[/import]