I am trying to add an attirubute to objects that i created.Here i created bird display objects but i want to add those birds a spesific attiribute like typeOfBird and then i want to reach those attiributes like bird.typeOfBird . How can i do that?
module(...,package.seeall)
function new(params)
local bird=display.newImage(params.img,params.x,params.y)
function bird:touch(event)
local t = event.target
local phase = event.phase
if "began" == phase then
-- Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true
elseif t.isFocus then
if "moved" == phase then
t.x = event.x
t.y = event.y
elseif "ended" == phase or "cancelled" == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
return true
end
It looks like bird objects are already simple lua tables,
so you can just get and set the values as normal. So for example you could add lines like:
and
to your
bird:touchfunction.Or
in your
newfunction.