Is it possible to reference a variable from a different script from my current one? for example if in script 1 I have VARIABLE1 = THING1 in my second script can I somehow tell it to use the VARIABLE1 variable? Thanks guys!
You have a couple options regarding what you are looking for.
First would be what we call Global Variables. You can declare a global variable by placing _G.
before the name of the variable. You will be able to call this variable from almost any script within your game file.
Script 1:
_G.bool = true -- Creates a global variable and assigns 'true' as the value
Script2:
print (_G.bool) --Should print 'true'
Another option would be to create a Module Script with variables you wish to use in multiple scripts. These work somewhat similar to global variables when you refer to them in other scripts.
Lets say you made a module script returned the array of variables called _M
. After you pull the module script into your new script, you can refer to the variables as _M.variable
or whatever you named the variable you created in the module script.
Example of module script:
_M = { bool = true } return _M
How to call the variable from another script:
_M = require('Path to Module Script') -- This will call the module script and return the variables print (_M.bool) --This should print 'true'
Let me know if this answers your question.