access object defined in module from main

Given the following:

example.lua

module(…, package.seeall)

function xyz()
local pgBtn = display.newRoundedRect(125, 400, 100, 70, 12)
pgBtn.strokeWidth = 3
pgBtn:setFillColor(51, 0, 255)
pgBtn:setStrokeColor(51, 153, 255)

midBtn:insert(pgBtn)

local pgBtntext = display.newText(abc, 145,415, native.systemFont, 50)

midBtn:insert(pgBtntext)
end

main.lua

require(“example”)

  1. how can I change the value of “abc” from main ?
  2. how can I change the fillcolor & strokecolorfrom main ?
    [import]uid: 31039 topic_id: 13799 reply_id: 313799[/import]

in main.lua use
abc = whatevervalue

and in example.lua use
_G.abc

thats it. :slight_smile:

check the below example…
this sample will give you a better idea

main.lua
[lua]local file2 =require(“file2”)
–global variable a
a = 10

file2:fn1()
–prints 10 – we din’t set _G.a in fn1
print(a)

file2:fn2()

–prints 25-- we set _G.a in fn2
print(a)[/lua]
file2.lua
[lua]module(…, package.seeall)

function fn1()

– prints 10 no other variable a, take the global one
print(a)

–create a new global variable a , won’t affect global a from main
a = 25

–prints 25
print(a)

–prints 10 – we haven’t set value to global a from main
print(_G.a)
end

function fn2()

–sets global variable a
_G.a = 25

–prints 25
print(a)

–prints 25
print(_G.a)
end[/lua] [import]uid: 71210 topic_id: 13799 reply_id: 50679[/import]

@renvis@technowand

Thx’s, just what I needed. [import]uid: 31039 topic_id: 13799 reply_id: 50925[/import]