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

GUI ( Menus )

Started by 1vannn, 26 November 2012 - 11:33 AM
1vannn #1
Posted 26 November 2012 - 12:33 PM
Does anyone know how you can make menus that goto other pages? Like 'Email' would goto a Email Client, etc..
Kingdaro #2
Posted 26 November 2012 - 01:33 PM
The other "pages" could be other programs, and you could just have a program display a menu, you press a corresponding key, and then open up a specified function.

Menu options could be stored in one table, while the programs they open could be triggered by another.


local options = {'Email','Music','Web Browser','Exit'}
local programs = {'email','music','webbrowser'}

while true do
  term.clear()
  term.setCursorPos(1,1)

  print 'Select an Option'
  print ''

  for i=1, #options do
    print(i..'. '..options[i])
  end

  local _, char = os.pullEvent('char')
  local num = tonumber(char)
  if num then
    if programs[num] then
      shell.run(programs[num])
    elseif options[num] == 'Exit' then
      shell.run('clear')
      break
    end
  end
end

This program would print:

Select an Option

1. Email
2. Music
3. Web Browser
4. Exit

And pressing 1, for example, would go to the email program.