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

Assigning table values to variables.

Started by camurro9, 03 September 2012 - 09:16 AM
camurro9 #1
Posted 03 September 2012 - 11:16 AM
Okay, before I start, I have had a look for this all over google, but to be honest I'm not quite sure what to search for.

okay, so I have a directory and inside it are, let's say, 6 files, but this might change such that today it's 6 files, tomorrow its 8, the day after it's 4.

fileA, fileB etc….

I can print the files with:


Table = fs.list("\file")
for i =1,#table do
write( table[i])
write("\n")
end

and this would give me a list with all the files in them. hooray!

but what I want is each value assigned to a variable, so that var1= "fileA", var2 = "fileB" and so on…
There might be a really simple way to do this but I think I'm missing something….
KaoS #2
Posted 03 September 2012 - 11:21 AM
you already have a full list, Table[1] is the first file, Table[2] is the second file etc
camurro9 #3
Posted 03 September 2012 - 11:34 AM
Yep, that should have been obvious. I'm kind of new to tables :D/>/> .

Thanks!
KaoS #4
Posted 03 September 2012 - 11:59 AM
no problem, tables are one of the best features in Lua in my opinion, you should try learn as much about them as you can