Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This is the computer transmitter turtle controler
- -- Modified movement code from PhyscoKillerMonkey post at http://www.computercraft.info/forums2/index.php?/topic/5665-wireless-goto-program-for-gps-turtles/page__fromsearch__1
- -- Modified menu code from JokerRH post at http://www.computercraft.info/forums2/index.php?/topic/11696-press-any-key-to-continue-scroll-enter/
- -- Modified by Richard Reigens 10/12/2013
- rednet.open("bottom") --Open rednet, make clearing the screen a single function
- function clear() term.clear() term.setCursorPos(1, 1) end
- exiting = false
- goTo = function()
- rednet.send(id, "goto") --When a waiting turtle is found send the command (goto) to its ID so it can ready for the transmission of coordinates
- clear()
- print("Enter goto coordinates")
- print("Enter X")
- local gox = tonumber(io.read()) --Get the coordinates from the player, they could be acquired by another means if needed
- clear()
- print("Enter Y")
- local goy = tonumber(io.read())
- clear()
- print("Enter Z")
- local goz = tonumber(io.read())
- clear()
- print("Coordinates are: ")
- print("X: ",gox)
- print("Y: ",goy)
- print("Z: ",goz)
- print("Sending coordinates")
- rednet.send(id, tostring(gox)) --Convert the coordinates to strings (as rednet only sends strings) and send them to the waiting turtle
- sleep(0.5)
- rednet.send(id, tostring(goy))
- sleep(0.5)
- rednet.send(id, tostring(goz))
- end
- goHome = function() -- send command to start gohome.lua
- rednet.send(id, "gohome")
- end
- goComp = function() -- send command to start gotopc.lua
- rednet.send(id, "gocomp")
- end
- exit = function() -- exits back to shell
- clear()
- exiting = true
- end
- while not exiting do
- clear()
- textutils.slowPrint("Richys Remote Turtle Controller!", 10)
- print("")
- print("Connected, ID: ", os.computerID())
- textutils.slowPrint("Listening for turtles....")
- id, msg = rednet.receive() --Wait for a turtle to say it is "Listening"
- if msg == "Listening" then
- print("Turtle found!!!")
- sleep(2)
- clear()
- local options = { -- Menu options First part is text to be shown on screen, second part is name of the above function to be called if that text is selected
- {"Goto a position", goTo},
- {"Go Home", goHome},
- {"Go to Main Computer", goComp},
- {"Exit", exit}
- }
- local selected = 1
- function draw()
- --Set the position for the first option. Change the second number if you want a headline or so...
- print("")
- term.setCursorPos(12, 2)
- print("Richys Remote Turtle Controller")
- print("")
- print("What you would like your turtle to do")
- print("")
- --Iterate over any option and print them on the screen
- for ind, param in ipairs(options) do
- --Clear line
- term.clearLine()
- --Print with or without marker
- if selected == ind then
- print(">"..param[1])
- else
- print(" "..param[1])
- end
- end
- end
- function run()
- while not exiting do
- --Pull the event
- local _, key = os.pullEvent("key")
- if key == keys.up and selected > 1 then
- --Decrement selected.
- selected = selected - 1
- elseif key == keys.down and selected < #options then
- --Increment selected.
- selected = selected + 1
- elseif key == keys.enter then
- --Run the function saved in the second slot of the currently selected option.
- options[selected][2]()
- break
- end
- --Redraw the screen
- draw()
- end
- end
- draw()
- run()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement