Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PASTE FNbnMgtK
- -- Open modem
- local modem = peripheral.find("modem")
- modem.open(2)
- -- Load in software library
- local sl = require("softwareLib")
- -- Set color scheme to default
- local function defaultColors()
- sl.fill(colors.lightBlue)
- sl.color(colors.black)
- end
- -- Set colors scheme to submenu scheme
- local function subColors()
- sl.fill(colors.white)
- sl.color(colors.black)
- end
- -- List connected turtles
- local function checkConnections()
- subColors()
- sl.panel(4,4,sl.getWidth() - 6, sl.getHeight() - 6)
- sl.xyCenteredText("Checking connections...")
- modem.transmit(1,2,"CheckConnection")
- defaultColors()
- -- Wait for responses from turtles
- local numConnected = 0
- os.startTimer(3)
- local event, peripheral_name, channel, replyChannel, message, distance
- while event ~= "timer" do
- event, peripheral_name, channel, replyChannel, message, distance = os.pullEvent()
- if event == "modem_message" and message == "CheckConnection true" then
- numConnected = numConnected + 1
- end
- end
- -- Display number of connected turtles
- sl.text(1,sl.getHeight(),numConnected .. (numConnected == 1 and " turtle" or " turtles") .. " connected")
- end
- -- Sync turtles' individual maps
- local function syncMap()
- modem.transmit(1,2,"GetMap")
- -- Wait for responses from turtles
- os.startTimer(5)
- local event, peripheral_name, channel, replyChannel, message, distance
- while event ~= "timer" do
- event, peripheral_name, channel, replyChannel, message, distance = os.pullEvent()
- if event == "modem_message" and string.sub(message, 1, 7) == "GetMap " then
- end
- end
- -- Sync maps
- -- Set all turtles to use the new synced map
- end
- -- Command turtles to go to a location
- local function move()
- local function goHome()
- local x,y,z = gps.locate()
- modem.transmit(1,2,"GoAbsolute " .. x .. " " .. y .. " " .. z)
- end
- local function moveRelative()
- end
- local function moveAbsolute()
- end
- -- Draw menu
- subColors()
- sl.panel(3,3,10,6)
- sl.text(4,4,"MOVE")
- sl.menu(4,5,1,
- {sl.menuOption("Home", goHome),
- sl.menuOption("Relative", moveRelative),
- sl.menuOption("Absolute", moveAbsolute)})
- defaultColors()
- end
- -- Command turtles to explore
- local function explore()
- modem.transmit(1,2,"Explore")
- end
- -- View the current map
- local function viewMap()
- -- Ask the user if they want to sync the map first
- subColors()
- sl.panel(4,4,sl.getWidth() - 6, sl.getHeight() - 6)
- sl.text(6,4,"SYNC FIRST?")
- -- Sync the map first
- local function yes()
- syncMap()
- no()
- end
- -- Don't sync the map first, just view
- local function no()
- -- Show map
- -- Set color scheme back to normal
- defaultColors()
- end
- -- Menu to sync map
- sl.xyCenteredMenu(1, {sl.menuOption("Yes", yes), sl.menuOption("No", no)})
- defaultColors()
- end
- -- Show main menu
- local function mainMenu()
- -- BG
- defaultColors()
- sl.panel(0,0,sl.getWidth() + 2, sl.getHeight() + 2)
- sl.panel(1,1,sl.getWidth(), sl.getHeight() - 1)
- -- Menu
- sl.text(3,1,"TURTLE COMMANDER")
- checkConnections()
- while true do
- sl.panel(1,1,sl.getWidth(), sl.getHeight() - 1)
- sl.text(3,1,"TURTLE COMMANDER")
- sl.xyCenteredMenu(1,
- {sl.menuOption("Check Connections", checkConnections),
- sl.menuOption("Sync Map", syncMap),
- sl.menuOption("Move", move),
- sl.menuOption("Explore", explore),
- sl.menuOption("View Map", viewMap)})
- end
- end
- -- Program logic
- mainMenu()
Add Comment
Please, Sign In to add comment