Hi, i’m newbie en Lua & Corona
I need to create several image objects in the screen; and i want to touch everyone and call to an event.
I have one class called “dog”. When the touch event is fired from an instance it make an error:
?:0: attempt to call a table value
and stop the debugger on: group:insert( matrix[row][line].GetImage() ) line.
Any suggestion?
Thanks!!
dog.lua
[code],
local dog = {}
local dog_mt = { __index = dog } – metatable
local image
function dog.new( nimage, x, y ) – constructor
image = display.newImage( nimage,x,y )
image.touch = dog
image:addEventListener( “touch”, image )
return setmetatable( newDog, dog_mt )
end
function dog:touch( self, event )
print( self.name )
end
function dog.GetImage()
return image
end
[/code],
main.lua
[code]
local dog = require( “dog” )
local matrix = {}
local group = display.newGroup()
– Display
for row = 1, 10 do
matrix[row] = {}
for line = 1,10 do
matrix[row][line] = dog.new( “dog.png”, 20, 20 )
group:insert(matrix[row][line].GetImage())
end
end
[/code],
[import]uid: 209287 topic_id: 36180 reply_id: 336180[/import]