1
votes

How to get access to table saved by another lua script with its unique name?

I tried to use in one script like:

_G.Value =12345 or _G["Value"]=12345

in the other script it does not read:

_G.Value or _G["Value"]

Is there any other way? Thanks in advance!

1
What is the environment? in some cases scripts exist in their own sandbox unable to "interfere" with other executing scripts' states. - Nifim

1 Answers

1
votes

If you want to access a global variable from another file, place require "firstfile.lua" in the top of the second file. This will work for _G or any other variable.

My code:

--file 1, "l1.lua"
value = "A"
print(_G.value)
--file 2, "l2.lua"
require "l1"
print(_G.value)

Executing lua l2.lua produces:

A
A

(One "A" for each print line in each file)