1

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. Commented Dec 27, 2019 at 17:26

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.