224 posts
Location
Auckland, New Zealand
Posted 28 January 2013 - 03:11 PM
Hello, I need some help. I've managed to get most of my code working BUT the menu Selection GUI is not working. Could someone help with this?
Pastebin link:
http://pastebin.com/WpRKYGUeThanks, AnthonyD98
7508 posts
Location
Australia
Posted 28 January 2013 - 03:27 PM
replace lines 58 and onwards with this
local s = 1
local mainOptions = {
{ "Programs", drawPrograms},
{"Control Panal", drawCP},
{"File Browser", drawFileGUI},
{"Command Prompt", drawCMD},
{"Exit to CraftOS", function() term.clear();termsetCursorPos(1,1);error();end},
{"Restart Computer", os.reboot},
{"Shutdown Computer", os.shutdown},
}
local function drawMenu()
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.clear()
term.setCursorPos(1,1)
cPrint("[ SelectOS ]")
space()
end
local function gui()
for i = 1, #mainOptions do
if s == i then
center("[>"..mainOptions[i][1].."<]", mainOptionsY + i)
else
center("[ "..mainOptions[i][1].." ]", mainOptionsY + i)
end
end
end
while true do
drawMenu()
gui()
local event, key = os.pullEvent("key")
if key == keys.down then
s = s + 1
if s >= #mainOptions then s = #mainOptions end
elseif key == keys.up then
s = s - 1
if s <= 1 then s = 1 end
elseif key == keys.enter then
mainOptions[s][2]()
end
end
if any of this needs explaining why i did it, just ask
224 posts
Location
Auckland, New Zealand
Posted 28 January 2013 - 03:39 PM
Thank you, for helping me :)/>
I didn't know you could use tables in that way, you've definatly teached me something :o/>
Thanks, AnthonyD98
7508 posts
Location
Australia
Posted 28 January 2013 - 03:49 PM
no problems :)/> if you want to see another way I use tables take a look here
https://raw.github.com/theoriginalbit/CCTube/develop/cctubemainly at the headerItems table and the
mouseClickedInElement and drawUrl functions