How do you access a local table within a touch event, such as the “touch” Listener? I am having troubles because the console error I receive says that my value is nil and that there is an error in indexing. Please help!!!
function new()
local myTable = {}
myTable ["firstValue"] = 1000
local myRect = display.newRect( 10,10,200,200)
local myText = display.newText(myTable.firstValue,50,300)
local function touchEvent(event)
if event.phase == "began" then
myTable.firstValue=myTable.firstValue+1000
myText.text = myTable.firstValue
end
end -- touchEvent
myRect:addEventListener("touch",touchEvent)
end -- new
new()
every time you touch the rectangle the value is implemented by 1000. [import]uid: 12635 topic_id: 6239 reply_id: 21525[/import]
Thanks guys! I really appreciate your help. My problem was that I had introduced the function before the table in my code and was therefore producing a nil when indexing the table. I didnt think that it mattered, but it does! Thanks for the quick responses:)