Hi guys,
I am building an application, and I am modularising it, to make it easy to maintain. Everything works fine, but I need some help or pointers in terms of accessing variables in different modules…
For example, I have an image on the screen… there is a button on the screen… when the button is pressed the image should dissapear… pretty easy?
The image is created in the main.lua file, the button is created in a gamefunctions.lua, which has the ontouch event… which is where the issue comes in… how do I access the image from main in gamefunctions.lua
Thanks in advance
Code posted
main.lua
[code]
local gameFunctions = require “gameFunctions”
local btnPressOK = true
local button
– Create New image
image1 = display.newImage(“reload.png”)
– Create button which hides and shows image
button = gameFunctions.createButtons()
[code]
gameFunctions.lua
[code]
module(…, package.seeall)
local ui = require(“ui”)
function createButton(originX, originY, sizeX, sizeY, imageBtnLocation,imageBtnPressedLocation)
local MenuBtn = ui.newButton{
defaultSrc = imageBtnLocation,
defaultX = sizeX,
defaultY = sizeX,
overSrc = imageBtnPressedLocation,
overX = sizeX,
overY = sizeX,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
MenuBtn.x = originX; MenuBtn.y = originY
return MenuBtn
end
function onbtnTouch()
print(“button Pressed”)
– when the button is clicked I want image1 to be hidden
– how do I access that variable from main
–main.image1.isVisible = false
end
function createButtons()
local btn = createButton(450, 300,48, 48, “next.png”, “next_p.png”)
btn:addEventListener(“tap”, onbtnTouch )
return btn
end
[code] [import]uid: 67619 topic_id: 15788 reply_id: 315788[/import]
[import]uid: 3826 topic_id: 15788 reply_id: 58306[/import]