Skip to content

Instantly share code, notes, and snippets.

@cobaltgit
Last active August 6, 2022 11:59
Show Gist options
  • Save cobaltgit/a2bbaeadb2e1889167aab616d59047d1 to your computer and use it in GitHub Desktop.
Save cobaltgit/a2bbaeadb2e1889167aab616d59047d1 to your computer and use it in GitHub Desktop.
A basic ComputerCraft program that allows control of a turtle from a wireless pocket computer using Rednet client/server API
--> Run this program on an (advanced) wireless pocket computer in your off-hand for best results
--> Replace 'id' with the id of the turtle - run the 'id' command in the turtle's shell
rednet.CHANNEL_BROADCAST = 8000
rednet.open("back")
print("Controller open on port "..rednet.CHANNEL_BROADCAST)
while true do
rednet.send(id, io.read())
end
--> This program must be run on an advanced wireless turtle
rednet.CHANNEL_BROADCAST = 8000
rednet.open("right")
print("Now listening on port "..rednet.CHANNEL_BROADCAST)
while true do
local id,msg = rednet.receive()
local action = "UNKNOWN"
msg = msg:lower()
for token in string.gmatch(msg, "[^%s]+") do --> split string by space
if token == "w" or token == "forward" then
action = "FORWARD"
turtle.forward()
elseif token == "a" or token == "left" then
action = "LEFT"
turtle.turnLeft()
elseif token == "s" or token == "back" then
action = "BACK"
turtle.back()
elseif token == "d" or token == "right" then
action = "RIGHT"
turtle.turnRight()
elseif token == "up" then
action = "UP"
turtle.up()
elseif token == "down" then
action = "DOWN"
turtle.down()
end
print("Received action "..action)
end
turtle.refuel() --> Infinite fuel!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment