Very new to Lua and computer craft.
The script displays the label, fuel, any active redstone signals, gps etc...
The problem :
at the tail end of the script I am using the parallel.waitForAny() function to either wait indefinitely for a rednet message, or upon an os.pullEvent("key")
it exits out into the shell. The rednet part of the parallel process seems to work fine. I can't figure out how to exit out of the script on a key press cleanly.
shell.exit() resulted in a black screen of death.
Right now I have it set to display the OS version, which quits out to a shell afterwards. Which does work, but it feels like a band aid fix.
Is there a better way to do it?
-- TurtleStart
-- Version 0.0.1
-- Build Status : Alpha
-- TurtleOS Version: 1.5
-- Author : Dngrzone
--Label
local label = os.getComputerLabel()
print("Name : ", label)
--Fuel
local gas = turtle.getFuelLevel()
print("Fuel Level:",gas)
--Peripheral
local wifi = peripheral.wrap('right')
rednet.open("right")
if rednet.isOpen("right") then
print("Wifi: ON")
else
print("Wifi: OFF")
end
--Check for active redstone signals
local redstoneLeft = redstone.getInput("left")
local redstoneRight = redstone.getInput("right")
local redstoneTop = redstone.getInput("top")
local redstoneBottom = redstone.getInput("bottom")
local redstoneFront = redstone.getInput("front")
local redstoneBack = redstone.getInput("back")
--Then Display them
print("Active Redstone: ")
print("T: ",redstoneTop)
print("L: ",redstoneLeft," F: ",redstoneFront," R: ",redstoneRight)
print("Bm: ",redstoneBottom," Bk: ",redstoneBack)
--GPS
local x, y, z = gps.locate(2)
if x ~= nil then
print("GPS: Active")
else
print("GPS: Out of Range")
end
-- The following section is not implemented due to the GPS towers not yet being deployed.
-- Getting Location
--local home = vector.new(home.x, home.y, home.z)
--local position = vector.new(gos.locate(5))
--local displacement = position - home
--print("Location: ", displacement.tostring(), " from home.")
--Display the console and wait for commands over wifi in the background
local wifiRX = function()
local TXid, message, distance = rednet.receive()
print("Received: ",message," From :", TXid)
print("Executing :", message)
shell.run(message)
end
local consoleInput = function()
print("Awaiting Rednet, press any key to override")
local event, key = os.pullEvent("key")
local version = os.version()
print(version)
end
parallel.waitForAny(wifiRX,consoleInput)
Also, any help on how to clean up the script, display the text better, etc.. would be greatly appreciated.
Constructive Criticism welcome.
Edited by dngrzone, 20 January 2014 - 10:09 PM.












