Advertisement
Guest User

demo4.lua

a guest
Sep 21st, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. local scr = require("screen") --Calls the library and labels it scr
  2. local event = require("event")
  3. local term = require("term")
  4.  
  5. local win = scr:newPane(win, 50, 25) --Sets up our new window as an object
  6. win:center() --Centres our window on the screen
  7. win:box(1, 1, 50, 25, 0x999999) --Adds a box the full size of our window.
  8. win:centerText(1, 10, 50, 0x999999, 0x000000, "You are not authorised to push this button.") --Adds centred text to line 10
  9. win:button("Do not push", 19, 12, 12, 3, 0xFF0000, "pushed") --Adds a button to the window that says Do not push. Returns "pushed" when --pressed.
  10. win:button("Stop me",19, 15, 12, 3, 0xFF0000, "stopme")
  11. win:render()
  12.  
  13. --That*s all we need in this window so now establish a run function...
  14.  
  15. local function run(ev, p1, p2, p3, p4, p5) --These Parameters are all the possible parameters that event.pull can give us.
  16.     if ev == "touch" then --This says that if the event was a screen click...
  17.         if win:clicked(p2, p3) then --This will take p2 and p3 (The x and y position of the click.) and see if it is within the window boundaries
  18.             ret = win:buttonClicked(p2, p3) --This does the same but for all the buttons in the window, we are looking for if ret equals "pushed"
  19.             ret2 = win:buttonClicked(p2, p3) --
  20.             if ret == "pushed" then --If the return value is "pushed"
  21.                -- win:move(math.random(1, 160), math.random(1, 50)) --This will move the window to a random screen position
  22.                 term.clear() --clear the screen
  23.                 win:render() --redraw the window
  24.             if ret2 == "stopme" then
  25.             term.clear()
  26. --            win:render()
  27.             term.setCursor(1,1)
  28.             term.write("This crap sucks")
  29.             running = false
  30.             end
  31.             end
  32.         end
  33.     elseif ev == "key_down" then --This is an easy exit program feature, any keypress will terminate the program
  34.         term.clear() --clear the screen so you*re not left with a window.
  35.         running = false --Tell the main loop to stop.
  36.     end
  37. end
  38.  
  39. --That should do for a run function so now we need to pull events in a loop
  40.  
  41. local running = true
  42. while running do
  43.     local ev, p1, p2, p3, p4, p5 = event.pull(.5, _, ev, p1, p2, p3, p4, p5) --This line starts queing events on the event stack and passes the variables
  44.     run(ev, p1, p2, p3, p4, p5) --To your run function.
  45. end
  46.  
  47. --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement