Guest User

move.lua

a guest
Aug 6th, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. local keymap = {
  2.     [340] = "up",
  3.     [341] = "down",
  4.     [87]  = "forward",
  5.     [265] = "forward",
  6.     [65]  = "turnLeft",
  7.     [263] = "turnLeft",
  8.     [83]  = "back",
  9.     [264] = "back",
  10.     [68]  = "turnRight",
  11.     [262] = "turnRight",
  12.     [32]  = "exit"
  13. }
  14.  
  15. while true do
  16.     local e, key, held = os.pullEvent("key")
  17.     local inst
  18.     for k, v in pairs(keymap) do
  19.         if k == key then
  20.             inst = v
  21.             break
  22.         end
  23.     end
  24.     if inst ~= nil then
  25.         if inst == "exit" then
  26.             return
  27.         end
  28.         term.write(inst)
  29.         if (turtle[inst])() then
  30.            print()
  31.        else
  32.            term.clearLine()
  33.            term.setCursorPos(1, select(2, term.getCursorPos()))
  34.        end
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment