Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to handle incoming commands
- local function handleCommand(command)
- if command == "forward" then
- turtle.forward()
- print("Moved forward")
- elseif command == "back" then
- turtle.back()
- print("Moved back")
- elseif command == "left" then
- turtle.turnLeft()
- print("Turned left")
- elseif command == "right" then
- turtle.turnRight()
- print("Turned right")
- elseif command == "up" then
- turtle.up()
- print("Moved up")
- elseif command == "down" then
- turtle.down()
- print("Moved down")
- elseif command == "mine" then
- turtle.dig()
- print("Block mined")
- else
- print("Unknown command:", command)
- end
- end
- -- Main loop
- while true do
- -- Make a request to the web server
- local response = http.get("http://71.68.68.110/get-command")
- -- If the request was successful and we received a command
- if response then
- local command = response.readAll()
- response.close()
- if command then
- print("Received command:", command)
- handleCommand(command)
- end
- end
- -- Wait for a short while before making the next request
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement