I am loading an external lua file full of functions that place commonly used objects on the stage. This works great, but I cannot figure out how to reference an object from within an event listener by name. For example:
[blockcode]
if (obj1 == “anvil1” and obj2 == “dude”) then
do something
end
[/blockcode]
In the example below I add a new anvil to the stage called “anvil1”. When trying to reference this within a collision function, it returns nil.
objects.lua
[blockcode]
function addAnvil(anvilName,x,y)
local anvilName = display.newImageRect( “anvil.png”, 50, 29 )
anvilName.x = x; anvilName.y = y
physics.addBody( anvilName, “kinematic”, { density=1, bounce=0, friction=1 } )
anvilName.myName = “anvil”
end
[/blockcode]
main.lua
[blockcode]
objects = require( “objects” )
objects.addAnvil(anvil1,180,80)
[/blockcode] [import]uid: 12877 topic_id: 7003 reply_id: 307003[/import]