Coming right up, just gotta get in the last few bits and pieces. :o/>/>
OK, I went over the code.
The main menu works, but the second menu I made comes up, but when I select a tank it goes back to the main menu. Can you se the error? (kinda like where's Waldo?"
but this is how its looking so far.
Spoiler
-- Big round of applause to Advert at Computercraft Forums for pretty mutch making everything in here... :o/>/>
function sleepWithPercent(n)
local startTime = os.clock() -- Get the starting time
local timer = os.startTimer(n) -- Create a timer so we know when to stop sleeping
local cursorx, cursory = term.getCursorPos() -- Save the cursor position to avoid spamming the terminal
local tick = os.startTimer(0) -- Create another timer so we can update the % shown on the terminal
for sEvent, t in os.pullEvent do -- Loop, with the results of os.pullEvent as sEvent and t
if sEvent == "timer" and t == timer then -- Check for the exit timer
term.setCursorPos(cursorx, cursory) -- Clean the screen
term.write(" ")
term.setCursorPos(cursorx, cursory)
break -- Break out of the loop
elseif sEvent == "timer" and t == tick then -- Check for the update timer
term.setCursorPos(cursorx, cursory)
tick = os.startTimer(0.1) -- Re-start the timer since timers only run once
local p = tostring(math.floor(((os.clock() - startTime) / n) * 100)) -- Calculate the %age
p = #p == 3 and p or (#p == 2 and ("0" .. p) or "00" .. p) -- Pad with 0s infront if it's not long enough
term.write(p .. "%")
end
end
end
-- clear screen function
local function clear()
term.setCursorPos(1,1)
term.clear()
end
local tChoices = {}
tChoices[0] = 'Pump from Main Oil Tank'
tChoices[1] = 'Pump to Main Oil Tank'
tChoices[2] = 'Pump to a remote remote location'
tChoices[3] = 'Pump to refinery'
tChoices[4] = 'Pump from Buffer Tank to Main Oil Tank'
table.insert(tChoices, 'Shutdown') -- If you add more stuff, the shutdown will always come at the bottom, without you having to change its #.
local nTermX, nTermY = term.getSize()
local sSeperator = ("-"):rep(nTermX) -- Create a seperator string with the size of the terminal
local tActions = {} -- Twin table of tChoices, we'll put functions in here to do stuff. !!!(still dont know what to do here?)!!!
tActions[0] = function(MpT) -- mpt = Main pump Tank
clear()
print(sSeperator)
print("| Pumping from Main Oil Tank |")
print(sSeperator)
print("Tank menu:")
print("1. Oil Tank 1")
print("2. Oil Tank 2")
print("3. Oil Tank 3")
print("4. Oil Tank 4")
term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
write("Select a Oil Tank to pump to: ")
select = read()
if select == 1 then
clear()
print(sSeperator)
print "| Oil Tank 1 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping to Oil Tank 1 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.blue)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
end
if select == 2 then
clear()
print(sSeperator)
print "| Oil Tank 2 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping to Oil Tank 2 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.lightblue)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
end
if select == 3 then
clear()
print(sSeperator)
print "| Oil Tank 3 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping to Oil Tank 3 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.purple)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
end
if select == 4 then
clear()
print(sSeperator)
print "| Oil Tank 4 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping to Oil Tank 4 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.cyan)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
else
clear()
print("!!! Invalid Selection !!!")
end
end
tActions[1] = function(TpM) -- TpM = Tank Pump Main
clear()
print(sSeperator)
print("| Pumping to Main Oil Tank |")
print(sSeperator)
print("Tank menu:")
print("1. Oil Tank 1")
print("2. Oil Tank 2")
print("3. Oil Tank 3")
print("4. Oil Tank 4")
term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
write("Select a Oil Tank to pump from: ")
select = read()
if select == 1 then
clear()
print(sSeperator)
print "| Oil Tank 1 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping from Oil Tank 1 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.white)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
end
if select == 2 then
clear()
print(sSeperator)
print "| Oil Tank 2 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping from Oil Tank 2 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.lightgrey)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
end
if select == 3 then
clear()
print(sSeperator)
print "| Oil Tank 3 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping from Oil Tank 3 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.grey)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
end
if select == 4 then
clear()
print(sSeperator)
print "| Oil Tank 4 selected |"
print(sSeperator)
write("How many seconds do you want to pump?: ")
t = io.read()
sleep(1)
clear()
print("Pumping from Oil Tank 4 for "..t.." Seconds...")
rs.setBundledOutput("top", colors.black)
term.write("Progress: ")
sleepWithPercent(t)
rs.setBundledoutput("top", 0)
clear()
print("Pumping Complete!")
else
clear()
print("!!! Invalid Selection !!!")
end
end
tActions[2] = function(MpR) -- Main pump Remote
term.clear()
term.setCursorPos(1, 1)
print("Function disabled untill I learn Lua")
term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
write(" [Press enter to return to main menu]")
read()
end
tActions[3] = function(MpRef) -- Main pump Refinery
term.clear()
term.setCursorPos(1, 1)
print("Function disabled untill I learn Lua")
term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
write(" [Press enter to return to main menu]")
read()
end
tActions[4] = function(BpM) -- Buffer pump Main
term.clear()
term.setCursorPos(1, 1)
print("Function disabled untill I learn Lua")
term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
write(" [Press enter to return to main menu]")
read()
end
table.insert(tActions, os.shutdown) -- Insert the shutdown function at the end to compliment the "Shutdown" menu item :)/>/>
-- Do the above for the remaining
local nSelection = 0 -- The current selection defaults at 0
repeat
term.setCursorPos(1, 1)
term.clear()
print(sSeperator)
print("| Oil Pump System Beta 1.0 |")
print(sSeperator)
for nLine = 0, #tChoices do -- Iterate through the possible options, and print them, marking the chosen one
local sLine = " "
if nSelection == nLine then
sLine = ">"
end
local sLineNum = tostring(nLine)
if #sLineNum < 2 then
sLineNum = "0" .. sLineNum -- Prepend a 0 if it's too short
end
sLine = sLine .. "[" .. sLineNum .. "]" .. " " .. tChoices[nLine] -- Construct the string we're printing
print(sLine) -- Print it
end
-- os.pullEvent keys: up - 200, down - 208, enter - 28
local sEvent, nKey = os.pullEvent("key") -- Using the 1.3 filtering; this will mean only "key" events will pass
if nKey == 200 or nKey == 17 then -- Up/w key: move up the menu
if tChoices[nSelection - 1] then -- Check if we can move up
nSelection = nSelection - 1
end
-- Ignore it otherwise
elseif nKey == 208 or nKey == 31 then -- Down/s key: move down the menu
if tChoices[nSelection + 1] then -- Check if we can move down
nSelection = nSelection + 1
end
elseif nKey == 28 then -- Enter key: Selecting a choice
if tActions[nSelection] then
tActions[nSelection]() -- Run the function associated with the action.
else
print("Error: Selection out of bounds: ", nSelection)
read() -- This error is recoverable.
end
end
until false -- Run this loop forever :)/>/>