Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --setup for key handlers
- local event = require "event" -- load event table and store the pointer to it in event
- local term = require "term"
- ship = component.warpdriveShipController
- local char_w = string.byte("w") -- numerical representation of the space char
- local char_s = string.byte("s")
- local char_e = string.byte("e")
- local char_p = string.byte("p")
- local running = true -- state variable so the loop can terminate
- --print("Press W to close and S to say SLUT E to enter text P to Vomit it back")
- function unknownEvent()
- -- do nothing if the event wasn't relevant
- end
- --end key handler setup
- --begin main code
- function mainmenu()
- term.clear()
- print("Press - to operate ship")
- end
- --main code ends here
- --key handlers begin here
- -- table that holds all event handlers
- -- in case no match can be found returns the dummy function unknownEvent
- local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end })
- -- Example key-handler that simply sets running to false if the user hits space
- function myEventHandlers.key_up(adress, char, code, playerName)
- if (char == char_w) then
- running = false
- elseif (char == char_s) then
- print("you pressed the s key slut")
- elseif (char == char_e) then print("Enter Some Text") j = io.read() print("input Accepted")
- elseif (char== char_p) then print("Computer Vomit:", j) mainmenu()
- end
- end
- -- The main event handler as function to separate eventID from the remaining arguments
- function handleEvent(eventID, ...)
- if (eventID) then -- can be nil if no event was pulled for some time
- myEventHandlers[eventID](...) -- call the appropriate event handler with all remaining arguments
- end
- end
- -- main event loop which processes all events, or sleeps if there is nothing to do
- while running do
- handleEvent(event.pull()) -- sleeps until an event is available, then process it
- end
- --end key handlers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement