Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local scr = require("screen") --Calls the library and labels it scr
- local event = require("event")
- local term = require("term")
- local win = scr:newPane(win, 50, 25) --Sets up our new window as an object
- win:center() --Centres our window on the screen
- win:box(1, 1, 50, 25, 0x999999) --Adds a box the full size of our window.
- win:centerText(1, 10, 50, 0x999999, 0x000000, "You are not authorised to push this button.") --Adds centred text to line 10
- 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.
- win:button("Stop me",19, 15, 12, 3, 0xFF0000, "stopme")
- win:render()
- --That*s all we need in this window so now establish a run function...
- local function run(ev, p1, p2, p3, p4, p5) --These Parameters are all the possible parameters that event.pull can give us.
- if ev == "touch" then --This says that if the event was a screen click...
- 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
- 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"
- ret2 = win:buttonClicked(p2, p3) --
- if ret == "pushed" then --If the return value is "pushed"
- -- win:move(math.random(1, 160), math.random(1, 50)) --This will move the window to a random screen position
- term.clear() --clear the screen
- win:render() --redraw the window
- if ret2 == "stopme" then
- term.clear()
- -- win:render()
- term.setCursor(1,1)
- term.write("This crap sucks")
- running = false
- end
- end
- end
- elseif ev == "key_down" then --This is an easy exit program feature, any keypress will terminate the program
- term.clear() --clear the screen so you*re not left with a window.
- running = false --Tell the main loop to stop.
- end
- end
- --That should do for a run function so now we need to pull events in a loop
- local running = true
- while running do
- 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
- run(ev, p1, p2, p3, p4, p5) --To your run function.
- end
- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement