--Way at the top
local x , y, z = 0,0,0
--Assignment of vars
--About halfway down code
local restoreVars = {"x","y","z","pretendThereAreMoreThings"}
function saveProgress()
file = fs.open("fileName", "w")
for i=1, #restoreVars do
file.write(restoreVars[i].." = "..tostring(setfenv(loadstring("return "..restoreVars[i]),getfenv())()).."\n")
end
file.close()
end
--Later
local function mine()
--Do mining stuff
saveProgress()
end
Now, the writing part works, but the part with loadstring does not. The output file gets x = nil y = nil z = nil everythingElse = nil
Also, just to break down the complicated part involving loadstring, it setting the environment of the function returned by loadstring to the program's local global environment (so it can see variables theoretically). Then it calls that function to return the value of the variable in the program, and tostrings it.
What am I doing wrong?












