749 posts
Location
BOO!!
Posted 28 April 2016 - 01:10 PM
--File A
local txt = 'works'
_G.printer = function()
print(txt)
end
--File B
printer()
--Returns 'works'
txt = 'this is where my problem lies'
printer()
--Returns 'this is where my problem lies'
Edited on 28 April 2016 - 11:11 AM
1023 posts
Posted 28 April 2016 - 02:10 PM
Edit misread question
Edited on 28 April 2016 - 12:12 PM
1243 posts
Location
Indiana, United States
Posted 28 April 2016 - 02:10 PM
Have you tried making txt local in File B? It's probably overwriting the reference to txt in _G.printer since you're not specifying local for the File B declaration.
Edit: Ninja'd by valithor, but I don't quite think he got the problem.
Edited on 28 April 2016 - 12:11 PM
7083 posts
Location
Tasmania (AU)
Posted 28 April 2016 - 02:20 PM
Have you tried making txt local in File B? It's probably overwriting the reference to txt in _G.printer
It won't either way, or at least, assuming the code shown here is complete. It simply can't do it without modifying the environment of the function in concern.
This makes me assume that the question is "how do I make it act like this", in which case valithor's on the right track in asking "why?" (though the short answer is "lookup getfenv()/setfenv()").
If it really
is acting the way he describes already, then either he's not running the code he's showing us, or he's using an emulator or sandbox or… something with a really weird bug.
749 posts
Location
BOO!!
Posted 28 April 2016 - 02:49 PM
It previously did it? With the same code. That's strange.
Edited on 28 April 2016 - 12:51 PM