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

Looking for some Information

Started by cory1234567, 20 January 2013 - 02:34 PM
cory1234567 #1
Posted 20 January 2013 - 03:34 PM
if i wanted to call a variable from a different file how would i go about doing it

Main
Variables

if i wanted to call a variable from Variables into the main program

if u dont know what im trying to ask then tell me and ill try to explane it in more detail

thanks for any help
Bubba #2
Posted 20 January 2013 - 04:31 PM
Well the way you've worded this is a bit confusing, but as far as I can tell you're asking for how you might read a variable from another file. If that is indeed the case, then try this:


local f = fs.open("youfile", "r")
local content = {}
local sRead = f.readLine()
while sRead do
  table.insert(content, sRead)
  sRead = f.readLine()
end
f.close()

Now the table 'content' has the entire file in it separated by lines. If you have the information you want stored on line two, content[2] will have that line. If you need to convert that information to a number, just use tonumber(content[2]).
cory1234567 #3
Posted 21 January 2013 - 11:01 AM
i found an easier way by doing dofile("filename") but thanks for the input
theoriginalbit #4
Posted 21 January 2013 - 11:04 AM
i found an easier way by doing dofile("filename") but thanks for the input
That will probably be the easiest way for you to do it.