Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ws = http.websocket("wss://cc-epoch-interface.glitch.me")
- if not ws then error("WebSocket connection failed") end
- print("Attempting communication...")
- ws.send("turtle new")
- while true do
- local message = ws.receive()
- local words = {}
- for word in message:gmatch("%w+") do
- table.insert(words, word)
- end
- print(message)
- case = {
- move = function()
- if words[2] == "w" then
- turtle.forward()
- elseif words[2] == "a" then
- turtle.turnLeft()
- elseif words[2] == "s" then
- turtle.back()
- elseif words[2] == "d" then
- turtle.turnRight()
- elseif words[2] == "space" or words[2] == "q" then
- turtle.up()
- elseif words[2] == "shift" or words[2] == "z" then
- turtle.down()
- elseif words[2] == "i" then
- turtle.digDown()
- elseif words[2] == "o" then
- turtle.dig()
- elseif words[2] == "p" then
- turtle.digUp()
- end
- end,
- default = function()
- print("Unrecognized command "..words[1])
- end,
- }
- -- execution section
- if case[words[1]] then
- case[words[1]]()
- else
- case["default"]()
- end
- end
- ws.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement