Hi,
There used to be a tutorial here on the forums that showed how to create object-oriented modules, however I cannot seem to find it anymore.
Anyhow, in following the tutorial I created this for my game:
-- -- main.lua -- local d = require("d") local bot = require("bot") local bot1 = bot.new(100,200) -- Create bot in main.lua file for gameplay -- Would like for the touch listener to already be applied to the bot when created here
-- -- bot.lua -- local bot = {} local bot\_mt = { \_\_index = bot } local d = require("d") ------------------------------------------------- function bot.new(x, y) -- constructor print("bot.new") local o = display.newRect(x,y,32,32) o:setFillColor(0) camera:add(o,1) return setmetatable(o, bot\_mt) end function bot:remove() print("bot:remove") end -- Touch listener for the bot function bot:touch() print("bot:touch") end ------------------------------------------------- return bot
However, I cannot seem to get the touch listener to get to work for the bot object in the module so it applies to all created instances in the main.lua file.
If my file setup is outdated, or there is something I am completely missing, any advice would be greatly appreciated.
Thank you
