Than you so much horacebury, that is correct!!
but I had to move the function o.onTrottle before the o.tableForListeners and I could not use self on the value that represent the function it will call, I had to do: o.onTrottle and not self.onTrottle
So:
- the function: o.onTrottle()
[LUA]
function o.onTrottle()
print(“Trottle function”)
end
[/LUA]
- The table that holds the values for both obj and function for the event listener: o.tableForListeners:
[LUA]
o.tableForListeners = {
{self.hudTrottle, o.onTrottle}
}
[/LUA]
- The generating of the event listener inside the function: o.startListener:
[LUA]
function o.startListeners()
self.hudPanelOff.isVisible = false
for k,v in pairs (o.tableForListeners) do
v[1]:addEventListener( “touch”, v[2] )
end
end
[/LUA]
Now it all works
Now I start to wonder WHY could´t I use self on the last value?? in:
[LUA] {self.hudTrottle, o.onTrottle}[/LUA]
My own guess is this:
self.hudTrottle is referring to the variable declared in the prototype of the metatable (outside the :new() constructor so it is legit for self to reference to and the onTrottle is declared inside the :new()´s constructor and NOT in the root of the module ( _M={} )
…thats why I have to refer to it as o and not as self
…any comments regarding this is appreciated !!