This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MarioBG's profile picture

Reading variables from files

Started by MarioBG, 08 July 2015 - 08:23 AM
MarioBG #1
Posted 08 July 2015 - 10:23 AM
Hello!
I've been working on my OS for quite some time now, and I have run into the need to implement in my API a function to read variables out of files. These can be, and usually are, standard programs which happen to have a variable that I need in my main loop to execute them properly. How do I do this? The desired output would be a table similar to that returned by os.loadAPI, but with variables instead of functions, the index being the variable name and the value, its value. Thanks a lot!
KingofGamesYami #2
Posted 08 July 2015 - 03:22 PM
Lets say your file is named config, and it looks like this:

textColor = colors.blue
backgroundColor = colors.black

You could simply do this:

os.loadAPI( "config" )
term.setTextColor( config.textColor )
term.setBackgroundColor( config.backgroundColor )

…because os.loadAPI gets all globally declared variables. Obviously, if you localize your variables (as with functions) they will not be available.