9551

smol API

Aug 17th, 2021 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local function API(ins, cord1, cord2, length, height)
  2.     if ins == true then
  3.         ins = {os.pullEvent("monitor_touch")}
  4.     end
  5.     if ins[3] >= cord1 and ins[3] <= cord1 + length - 1 then
  6.         if ins[4] >= cord2 and ins[4] <= cord2 + height - 1 then
  7.             return true
  8.         else
  9.             return false
  10.         end
  11.     end
  12. end
  13. local function timetouch(timeout, mon)
  14.     local timer = os.startTimer(timeout)
  15.     while true do
  16.         local event = {os.pullEvent()}
  17.         if (event[1] == "timer") and (event[2] == timer) then
  18.             if mon == nil then
  19.                 local mon = "timeout"
  20.             end
  21.             return {"timeout", mon, 1000, 1000}
  22.         elseif (event[1] == "monitor_touch") and (event[2] == mon) then
  23.             return {event[1], event[2], event[3], event[4]}
  24.         end
  25.     end
  26. end
  27. local function button(mon, ins, cord1, cord2, text)
  28.     if ins[2] == mon then
  29.         if ins ~= nil then
  30.             local m = peripheral.wrap(mon)
  31.             local x = API(ins, cord1, cord2, string.len(text), 1)
  32.             m.setCursorPos(cord1, cord2)
  33.             m.write(text)
  34.             return x
  35.         end
  36.     end
  37. end
  38.  
  39. return {
  40.     API=API,
  41.     timetouch=timetouch,
  42.     button=button
  43. }
Add Comment
Please, Sign In to add comment