shamim
shamim

Reputation: 6768

In lua how to use load file variable in main file

my main file syntax is bellow

dofile("subFile.lua")
main('a')
print(subVariable)

my sub file syntax is bellow

local subVariable=""
function main(x)
 subVariable="from sub"
end

my subfile contain variable named subVariable want to use this variable in my main file ,why i always get nil.

How to use main file variable in subfile and subfile variable in main file

Upvotes: 2

Views: 765

Answers (1)

EinsteinK
EinsteinK

Reputation: 755

You're using a local. Remove the " local" and it'll work.

Locals are only accessible by the functions and code behind it.

Upvotes: 2

Related Questions