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

programs list

Started by Crowdy199, 22 November 2012 - 12:21 AM
Crowdy199 #1
Posted 22 November 2012 - 01:21 AM
ok guys i need your help with the code i want to make a program list but i want to make it so theres there per page and when u hold click u can slide and go to a second page and when u clikc the program it runs i really need help thanks
Goof #2
Posted 22 November 2012 - 05:04 AM
if you are new to lua, or just ComputerCraft, then i think you should start with some basics.. else… you should try looking at the advanced computers APIS.. it has the mouse event.. then you could learn a bit about it…

This section is not, for creating the code for you… its to correct the code you've got so far…
billysback #3
Posted 22 November 2012 - 09:15 AM
Let's start with the basics of getting a list;

local list = fs.list(dir)

now to open that list in to a "tree" we could do:

local function makeTree(root, list)
	local tree = {}
	for i=1,#list do
		local item = list[i]
		if fs.isDir(item) then
			 tree[#tree + 1] = makeTree(root.."/"..item, fs.list(root.."/"..item))
		else
			 tree[#tree + 1] = item
		end
	end
	return tree
end

now to print that tree on to the screen you just do:

local function printTree(tree, tab)
	for i=1,#tree do
		local item = tree[i]
		if type(item) == "string" then
			 print(tab..item)
		else
			 printTree(item, tab.."  ")
		end
	end
end

splitting that up in to pages would be a little bit harder, but for now I'll leave you with those and you can try and figure out the rest, keep asking if you don't understand what the code does or need help with certain bits, just don't ask for us to program an entire program for you.