How to call commands from an external module?

I’m getting this error when calling “settingsBTN.isVisible = true” from settings.lua module.
LINE 68: ERROR: “(attempt to index global ‘settingsBTN’ (a nil value))”

If there is a better way of doing this, I would appreciate help.
(This is only partial code.)

[code]
– file main.lua
require(“menu”)
require(“settings”)
menu.screen()
– file menu.lua
module(…, package.seeall)

function screen()
– Create menu
local menuGroup = display.newGroup()

– Display menu screen
local menuBG = display.newImageRect(“menu.png”, _W, _H)
menuBG.x = _W * 0.5; menuBG.y = _H * 0.5
menuGroup:insert(menuBG)

– Settings button
local settingsBTN = display.newImageRect(“settingsBtn.png”, 270, 36)
settingsBTN.x = 312; settingsBTN.y = 247
settingsBTN.name = “settingsBTN”
menuGroup:insert(settingsBTN)

local function init(event)

– SETTINGS
if (event.target.name == “settingsBTN”) then

settingsBTN.isVisible = false
settings.screen()

end
end

settingsBTN:addEventListener(“tap”, init)
end
– file settings.lua
module(…, package.seeall)

function screen()

– Create settings screen
local settingsGroup = display.newGroup()

– Display settings background screen
local settingsBG = display.newImageRect(“settings.png”, 300, 300)
settingsBG.x = _W * 0.5; settingsBG.y = _H * 0.5
settingsGroup:insert(settingsBG)

– Back button
local backBTN = display.newImageRect(“backBtn.png”, 270, 20)
backBTN:setReferencePoint(display.TopLeftReferencePoint)
backBTN.x = 95; backBTN.y = 280
backBTN.name = “backBTN”
settingsGroup:insert(backBTN)

local function init(event)
– SAVE SETTINGS AND GOTO MAIN MENU
if (event.target.name == “backBTN”) then
– Cleanup settings screen
display.remove(settingsGroup)
settingsGroup = nil

settingsBTN.isVisible = true end
end

backBTN:addEventListener(“tap”, init)
end
[/code] [import]uid: 53445 topic_id: 11002 reply_id: 311002[/import]

Hey there, try changing it to this;

[lua]menu.settingsBTN.isVisible = true[/lua]

Does that work?

I’m a little rusty on this but believe it should; let me know and if not will take a proper look at one of my older projects I’m sure I needed this for :slight_smile:

Peach [import]uid: 52491 topic_id: 11002 reply_id: 40111[/import]

I’m not in front a my dev machine at the moment so I can’t be positive but it looks like your modules are not returning anything. The “menu.screen()” call in your “main.lua” is calling the “screen()” funtion but the funtion is not sending anthing back. Try adding:

return settingsGroup

to the end of the function (befor the last “end” statement) [import]uid: 27965 topic_id: 11002 reply_id: 40136[/import]

O.k I tried “menu.settingsBTN.isVisible = true”, but unfortunately I’m getting the same error.

So I removed “local” from "local settingsBTN = display.newImageRect(“settingsBtn.png”, 270, 36)
and now this works “menu.settingsBTN.isVisible = true”

Do I need “local” on my “display.newImageRect” lines inside a group?
I’m using this to clean my group:
– Cleanup menu screen
display.remove(menuGroup)
menuGroup = nil

EDIT: I tried return settingsGroup, but did not work.

Thank you,
Mike
[import]uid: 53445 topic_id: 11002 reply_id: 40138[/import]