Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local code = 0 -- set the key code to 0
- local check = "" -- Set check to blank string
- local tid = 24 -- this is our turtle's ID that we want to control.
- rednet.open("top") -- my modem is on the top of the computer
- -- handy little bit of code that outputs the ID of the computer on every startup.
- local cmpid = os.getComputerID()
- print(cmpid)
- function test() -- Function to get key press
- check, code = os.pullEvent("key")
- end
- function rectur() -- Function to recieve message
- sid, msg = rednet.receive(1)
- if sid == nil then
- print("Turtle destroyed or out of range")
- end
- end
- while true do -- infinite loop
- test() -- Get the keypress. I made it a function because I thought it would be called multiple times.
- if code == 200 then -- 200 is the up arrow
- rednet.send(tid, "forward")
- rectur()
- elseif code == 203 then -- 203 is the left arrow
- rednet.send(tid, "left")
- rectur()
- elseif code == 205 then -- 205 is the right arrow
- rednet.send(tid, "right")
- rectur()
- elseif code == 208 then -- 208 is the down arrow
- rednet.send(tid, "back")
- rectur()
- elseif code == 54 then -- 54 is the shift key
- rednet.send(tid, "up")
- rectur()
- elseif code == 157 then -- 157 is the CTRL key
- rednet.send(tid, "down")
- rectur()
- elseif code == 28 then -- 28 is the enter key
- rednet.send(tid, "dig")
- rectur()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement