Advertisement
hevohevo

CC: rc_send1

May 2nd, 2016
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. -- rc_send1
  2. -- タートルをラジコンにするプログラム(リモコン側)
  3.  
  4. -- Config
  5. local id = 65535  -- 送信先ID
  6.  
  7. -- Functions
  8. function init()
  9.   term.clear()
  10.   term.setCursorPos(1,1)
  11.   print("  w  ")
  12.   print("a   d")
  13.   print("  s  ")
  14. end
  15.  
  16. -- Condition Table
  17. local cond = {}
  18. cond["w"] = "go_forward"
  19. cond["a"] = "strafe_left"
  20. cond["d"] = "strafe_right"
  21. cond["s"] = "go_back"
  22.  
  23. -- Main
  24. rednet.open("back")  -- ポケットコンピュータは後ろ側にモデムがある
  25.  
  26. while true do
  27.   init()
  28.   local event, moji = os.pullEvent("char")
  29.   print(moji)
  30.  
  31.   if cond[moji] then  -- もし送信メッセージを取り出すことができたら、
  32.     rednet.send(id, cond[moji])
  33.   else  -- そうでなければ、
  34.     print("wrong moji")
  35.   end
  36.  
  37.   os.sleep(2)
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement