Coding help, need sound to be associated with collision

Anyways I used the forums to get an answer to this and what I’m not too sure about is the event.other.objectName part underneath the groungTouch function. Basically all I want to do is have the crates make a (knock) sound when they hit the floor. (the locals for the ground and knock sound are already inserted before this segment).

[lua]local function trackOrbs (obj)
obj: removeSelf ()
end

local function spawncrate ()
local crate = display.newImageRect (“egg.png”, 45, 45);
physics.addBody (crate, {friction= 0.5, bounce= 0.3})
crate.x = math.random(300); crate.y = -100;

function crate: touch (e)

if (e.phase == “began”) then
trackOrbs (self);
audio.play (sound)

end
end

function groundTouch: (e)
if(e.phase == “began”) then
if (event.other.objectName == “ground”) then
audio.play (knock)
end
end
end

crate: addEventListener (“touch”, crate);
crate: addEventListener (“collision”, groundTouch);
end

timer.performWithDelay (10, spawncrate, 2);[/lua] [import]uid: 35535 topic_id: 6749 reply_id: 306749[/import]

Not sure what’s not working for you but have you made sure you’ve assigned the objectName “ground” you’re testing against – as well as the variable “knock” – before? [import]uid: 10284 topic_id: 6749 reply_id: 23638[/import]

ie

[lua]local ground1=display.newImage(“ground”)
ground1.objectName=“ground”[/lua]

personally i would use “type”

[lua]ground1.type=“ground”[/lua]

but it doesnt matter what you call it.

the reason it is done like that in the collision is to check it only happens when colliding with objects who’s type/objectName is “ground” and not say “wall” or “player” or “platform”

j

[import]uid: 6645 topic_id: 6749 reply_id: 23649[/import]