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).

P.S. or if one of you guys can tell me how to post this code on these forums with their own little scroll down box withing my comment box that'll be cool too. Thanks guys!

local function spawncrate ()
local crate = display.newImageRect ("crate.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 == "ended") then
--trackOrbs (self);
--end

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>your code</lua>

and the Lua language forum isnt really the correct place for your question. i would try the "developer support", "game edition" or "new users"

this is about the Lua language itself, rather than the Corona API features

j

views:1340 update:2011/10/6 9:28:12
corona forums © 2003-2011