Guest User

gui

a guest
Nov 14th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. term.clear()
  2. width, height = term.getSize() -- gets the screen size
  3. local progs = {"", "", "" } -- makes a table for use later
  4. local progsrun = {"", "", ""  } -- ^^
  5.  
  6.  
  7. function round(val)
  8.   return math.floor(val + 0.5)
  9.   end -- a simple rounding program
  10.  
  11. function getCenter(length) -- A function that is used to find
  12.   length1 = string.len(length) -- the center of the page
  13.   center = width / 2 - length1 / 2
  14.   return center
  15. end
  16.  
  17. function title(title) -- A function that is used to generate the title
  18.   term.setCursorPos(getCenter(title), 1)
  19.   term.write(title)
  20.   term.setCursorPos(1, 2)
  21.   local var pos = 1
  22.   while pos <= width do
  23.     term.setCursorPos(pos, 2)
  24.     term.write("_")
  25.     pos = pos + 1
  26.   end
  27. end
  28.  
  29. function option( optna, optno, totoptno, progtorun, proargs) -- This is the function that is broken somewhere
  30.   local pos = round((height / (totoptno + 1) * optno) + 2 )
  31.   term.setCursorPos(getCenter(optna), pos)
  32.   term.write( optna )
  33.   table.insert(progs, optno, pos) -- This is the table function that im having the problem with as detailed in the OP
  34.   table.insert(progsrun, optno, progtorun) -- The error occurs here too
  35.   -- When activated do
  36.   -- shell.run ( progtorun, progargs )
  37. end
  38.  
  39. function detect() -- Function to control the cursor
  40.   cursorpos = 1
  41.   while true do
  42.     keyPress = os.pullEvent(char)
  43.       if keyPress == 200 then -- detect key presses and if its the down key
  44.         cursorpos = cursorpos - 1 -- reduce the cursor position by 1
  45.       else if keyPress == 208 then -- oes the opposite
  46.         cursorpos = cursorpos + 1
  47.       else sleep(1)
  48.     end
  49.     if cursorpos < table.getn(progs) then
  50.       cursorpos = cursorpos - 1
  51.     end
  52.     secpos = progs[cursorpos] -- looks at the position of the options based on the variable stored in the table from the option function
  53.     term.setCursorPos( 5, secpos) --
  54.     term.write("-->")
  55.     end
  56.   end  
  57. end    
  58. title( " Epic GUI " )
  59. option( "Portal Song - Still Alive", 1, 3, "play", "" )
  60. option( "Hey Me", 2, 3, "heyme", "")
  61. option( "cest bien", 3, 3, "optnamd", "")
  62. write(progs[1], progs[2]) -- This is how i found where the error was occuring
  63.  
  64. detect()
Advertisement
Add Comment
Please, Sign In to add comment