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

Common programs, and fixes

Started by Gumball, 19 September 2014 - 04:15 AM
Gumball #1
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"
Edited on 19 September 2014 - 04:20 AM
InputUsername #2
Posted 19 September 2014 - 02:31 PM
1. This hurts my eyes, use
 tags please!
2. What's the point of this thread?
3. Are you sure you're getting into the "very advanced stage"? The code doesn't really look what I'd call "advanced".
Dog #3
Posted 19 September 2014 - 06:19 PM
It seems to me that confusing an indexing variable for an array is not very advanced; as well. fs.list() does not 'load' files.

bluebird173, fwiw, you have a ways to go before you're dealing with advanced Lua programming and concepts. When I wrote the original code that you based this thread of off, it was to help you learn; not for you to copy, make small changes to, present it as a tutorial, and pretend that you understand it…when you clearly don't yet.

My best advice to you is to stop worrying about being advanced and focus on learning new things and applying them in code…and always feel free to ask questions in Ask A Pro - the rest will come in time. We all started out as beginners.
Edited on 19 September 2014 - 04:42 PM
Lyqyd #4
Posted 19 September 2014 - 07:40 PM
Locked. Questions should be posted in Ask a Pro. Tutorials (which this is not good enough to be) should be posted in the Tutorials section. There have been a number of people that have tried to start these centralized topics, but these things are already covered better elsewhere and very little, if any, value is added by creating a centralized topic.