25 posts
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
1190 posts
Location
RHIT
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]).
25 posts
Posted 21 January 2013 - 11:01 AM
i found an easier way by doing dofile("filename") but thanks for the input
7508 posts
Location
Australia
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.