249 posts
Location
In the universe
Posted 11 October 2012 - 03:36 AM
How could I set a variable for every file listed by this code:
list = fs.list("programs")
nfiles = #list
term.setCursorPos(1, 3)
for _,file in ipairs(list) do
print(file)
end
or give me a variable for every file and then print it?
Thanks :P/>/>
1111 posts
Location
Portland OR
Posted 11 October 2012 - 03:39 AM
If it is stored in a table it already has a var. Here's an example on how to print them. This depends on the structure of the table however and may vary slightly.
local list = {} -- declare as table
list = fs.list("programs")
for x=1, #list do
print(list[x])
end
The first record in the table is list[1], and it increments to list[2] etc etc..
Edited on 11 October 2012 - 01:40 AM
249 posts
Location
In the universe
Posted 11 October 2012 - 03:59 AM
but each file that is in the table can be stored as a variable, each variable for each file?
2217 posts
Location
3232235883
Posted 11 October 2012 - 04:09 AM
what you want is the global table
usage:
_G[<string>]
will get the variable of the strings name
249 posts
Location
In the universe
Posted 11 October 2012 - 03:45 PM
And how can I implement the global table?