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

[Question] [ Solved ] What have I done wrong in my code?

Started by AnthonyD98™, 28 January 2013 - 02:11 PM
AnthonyD98™ #1
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/WpRKYGUe

Thanks, AnthonyD98
theoriginalbit #2
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
AnthonyD98™ #3
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
theoriginalbit #4
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/cctube
mainly at the headerItems table and the mouseClickedInElement and drawUrl functions