Posted 19 September 2014 - 06:15 AM
Hi guys, iv'e seen alot of programs that haven't been answered or are just plain old buggy, and since im getting into the very advanced stage in ComputerCraft, I decided i'd post some of my code. I'll update this from time to time, feel free to post programs or bugs with fixes into the comments so I can add them, first off, here's a file lister, but it doesn't list it in an index table format, i.e.:
{
"/rom",
"/myDirectory"
}
it actually prints in a simple way, heres the code:
files = fs.list("") –loads all files/directories in the root directory
count = #files –this is reading something in a table format, but counts how many lines of files there are for the for loop that prints out the files. the # meants count a certain
–way. i.e. if it was counting something on a table, it counts the lines as if the table were serialized. If it was just text then it counts how many characters there are.
for a=1,count do –this loop is saying that variable "a" is the loops variable, and starts off on 1 line, then counts up to how many lines there were in variable count.
print(files[a]) –this is printing the files out, on an index or array, (I call them indexes) and reads the line according to the index, i.e. what or how many times the loop has
end –repeated. The end ends the loop.
Indexes, or you may call them arrays, are ways of finding certain parts of code or using variables to define a certain loop. I'll show a way you can use them here:
local indexTable = {
[1] = ("The 1 means index 1/ line 1 on index table "IndexTable"),
[2] = ("This is just the 2nd index/array")
}
print(indexTable[1]) –the [1] means print the first index in the index table "indexTable"
{
"/rom",
"/myDirectory"
}
it actually prints in a simple way, heres the code:
files = fs.list("") –loads all files/directories in the root directory
count = #files –this is reading something in a table format, but counts how many lines of files there are for the for loop that prints out the files. the # meants count a certain
–way. i.e. if it was counting something on a table, it counts the lines as if the table were serialized. If it was just text then it counts how many characters there are.
for a=1,count do –this loop is saying that variable "a" is the loops variable, and starts off on 1 line, then counts up to how many lines there were in variable count.
print(files[a]) –this is printing the files out, on an index or array, (I call them indexes) and reads the line according to the index, i.e. what or how many times the loop has
end –repeated. The end ends the loop.
Indexes, or you may call them arrays, are ways of finding certain parts of code or using variables to define a certain loop. I'll show a way you can use them here:
local indexTable = {
[1] = ("The 1 means index 1/ line 1 on index table "IndexTable"),
[2] = ("This is just the 2nd index/array")
}
print(indexTable[1]) –the [1] means print the first index in the index table "indexTable"
Edited on 19 September 2014 - 04:20 AM