Jump to content




Reading variables from files


  • You cannot reply to this topic
1 reply to this topic

#1 MarioBG

  • Members
  • 43 posts
  • LocationSpain (or Hisperia)

Posted 08 July 2015 - 09: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!

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 08 July 2015 - 02: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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users