Advertisement
spdkils

ComputerCraft Remote Controller

May 11th, 2021
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. local function try_move(key, channel, moves)
  2.     local left_arrow = 263
  3.     local right_arrow = 262
  4.     if moves[key] then
  5.         rednet.send(channel, moves[key])
  6.         print(moves[key])
  7.     elseif key == left_arrow then
  8.         moves[32] = 'dig'
  9.         rednet.send(1, moves[32])
  10.     elseif key == right_arrow then
  11.         moves[32] = 'place'
  12.         rednet.send(1, moves[32])
  13.     else
  14.         rednet.send(1, key .. " pressed")
  15.     end
  16. end
  17.  
  18. write('Enter the bot\'s id: ')
  19. local bot = tonumber(read())
  20.  
  21. shell.run('clear')
  22. rednet.open('back')
  23. local moves = {}
  24. moves[265] = 'up'
  25. moves[264] = 'down'
  26. moves[87] = 'forward'
  27. moves[65] = 'left'
  28. moves[83] = 'backward'
  29. moves[68] = 'right'
  30. moves[32] = 'dig'
  31. moves[29] = 'rs'
  32. moves[82] = 'inspect'
  33. while true do
  34.     local event, key = os.pullEvent("key")
  35.     shell.run('clear')
  36.     try_move(key, 0, moves)
  37.     local _, _, text = os.pullEvent("rednet_message")
  38.     print(text)
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement