Advertisement
crimbojimbo

Untitled

Apr 27th, 2024
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | Source Code | 0 0
  1. function OneChoice(option, exit,TC,STC)
  2.     local w,h = term.getSize()
  3.     local op1,op2 = 0, 0
  4.     while true do
  5.         if (string.len(option) >= (w-4)) then
  6.             return error("Too Long")
  7.         elseif (exit == true) then
  8.             term.setCursorPos(4,(h-1))
  9.             if (op1 == 1) then
  10.                 term.setTextColor(STC or colors.yellow)
  11.                 write("> "..option)
  12.             else
  13.                 term.setTextColor(TC or colors.black)
  14.                 write("> "..option)
  15.             end
  16.             term.setCursorPos(4,h)
  17.             if (op2 == 1) then
  18.                 term.setTextColor(STC or colors.yellow)
  19.                 write("> Exit")
  20.             else
  21.                 term.setTextColor(TC or colors.black)
  22.                 write("> Exit")
  23.             end
  24.         else
  25.             term.setCursorPos(4,h)
  26.             if (op1 == 1) then
  27.                 term.setTextColor(STC or colors.yellow)
  28.                 write("> "..option)
  29.             else
  30.                 term.setTextColor(TC or colors.black)
  31.                 write("> "..option)
  32.             end
  33.         end
  34.     local event, side, mx, my = os.pullEvent("monitor_touch")
  35.         if (my == (h-1) and op2 == 0 and op1 ~= 1) then
  36.             op1 = 1
  37.         elseif (my == h and op1 == 0 and op2 ~= 1) then
  38.             if (exit == false) then
  39.                 op1 = 1
  40.             else
  41.                 op2 = 1
  42.             end
  43.         elseif (my == (h-1) and op2 == 1) then
  44.             op2 = 0
  45.             op1 = 1
  46.         elseif (my == h and op1 == 1) then
  47.             op1 = 0
  48.             op2 = 1
  49.         elseif (my == (h-1) and op1 == 1) then
  50.             if (exit == true) then
  51.                 return 1
  52.             end
  53.         elseif (my == h and op2 == 1) then
  54.             if (exit == false) then
  55.                 return 1
  56.             end
  57.             return 2
  58.         end
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement