How can i save a value in a class and pass it to another class in corona?
I want to access ishold parameter outside the class A? Everything works fine on A, value turns true/false whenever objects is clicked.
I want to acces it in class B, but when i print values out comes that classB buttonish gets called before buttonish class A, so value never gets saved and it turns always false (value that is in the constructor A)
Any idea please?
Class A.lua
local a={} local a\_mt={\_\_index=card} function a.new(x,y) local a\_new={} a\_new.ishold=false a\_new.x=x a\_new.y=y a\_new.tap\_event\_listener=nil -- view. a\_new.view=display.newGroup() a\_new.view.x=a\_new.x a\_new.view.y=a\_new.y return setmetatable(a\_new, a\_mt) end -- listen to the group. function a:buttonish() local function event\_listener(event) if (self.ishold == true) then self.ishold = false self.view.y = 300 else self.ishold = true self.view.y = 257 end end self.tap\_event\_listener=event\_listener self.view:addEventListener("tap", event\_listener) end
Class B.lua
local a\_t=require("a") local b={} function b.new(x,y) b.a\_index=0 b.a\_list={} for i=1,5 do table.insert(b.a\_list, a\_t.new(x, y)) end end function b.a\_buttonish(a\_index) b.a\_index=a\_index -- as a button index reference. b.a\_list[a\_index]:buttonish() end
Class Main.lua
local b\_t=require("b") main.b=b\_t.new(150, 300) -- initialize for index=1,5 do b\_t.a\_buttonish(index) end