I would like help with this code in getting it more functional.
It reads the amount of contents in my chest, then it makes more wood/coal/coke as needed, up to the 6912 limit of the chest (full). I don't want the chest to fill up again until the chest has reach the last stack of 64. Then it should pulse the "makeWood" or "makeCoal" or the "makeCoke". I want it to pulse quickly, but not too fast, because I have a lamp attached to the system and I want to see it flash.
The problem I am running into right now is, once it starts to make COKE, the computer wont do anything else, and I need it to multitask read the other inputs and reacting accordingly, updating inventory amounts and pulsing the other outputs so they can do/make other items at the same time.
I have started the program… so any help you can provided is appreciated.
-- CLEAR & INITIALIZE TERMINAL SCREEN
term.clear()
term.setCursorPos(1,1)
print "Loader Control System v1.0"
term.setCursorPos(1,3)
print "System: Online"
-- CLEAR & INITIALIZE MONITOR SCREEN (TOP)
local mon = peripheral.wrap("top")
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(3,1)
mon.write "Loader Control System v1.0"
mon.setCursorPos(3,3)
mon.write "System: Online"
-- SET BUNDLED CABLE TO "BOTTOM" AND INITIALIZE IN/OUTPUTS (OFF)
rs.setBundledOutput( "bottom", 0 )
-- SET BUNDLEDCABLE TO "BOTTOM"
local CablePort = "bottom"
-- FUNCTIONS
-- PULSE
local function pulse(side, colors, time)
rs.setBundledOutput(side, colors)
sleep(time / 2)
rs.setBundledOutput(side, 0) -- 0 means no colors, so it turns the output off
sleep(time / 2)
end
-- SET LOOP
while true do
-- FUNCTIONS
-- PULSE
local function pulse(side, colors, time)
rs.setBundledOutput(side, colors)
sleep(time / 2)
rs.setBundledOutput(side, 0) -- 0 means no colors, so it turns the output off
sleep(time / 2)
end
-- INITIALIZE COALCOKE CHEST INVENTORY COUNTER WITH CURRENT INVENTORY COUNT
os.loadAPI("ocs/apis/sensor")
local chestCokeCount = sensor.wrap("left")
cokecount = 0
details = chestCokeCount.getTargetDetails("-6,0,-1")
for i = 1, #details.Slots do
if details.Slots[i].Size then
cokecount = cokecount + details.Slots[i].Size
end
end
-- PRINT CURRENT COALCOKE INVENTORY COUNT TO TERMINAL SCREEN
term.setCursorPos(1,5)
print("Coalcoke Inventory:", cokecount)
-- PRINT CURRENT COALCOKE INVENTORY COUNT TO MONITOR SCREEN (TOP)
mon.setCursorPos(3,5)
mon.write "Coalcoke Inventory:"
mon.setCursorPos(22,5)
mon.write(tostring(cokecount))
-- BUNDLED CABLE "INPUTS"
local rebootSystemButton = redstone.testBundledInput(CablePort, colors.lime)
local resetCounterButton = redstone.testBundledInput(CablePort, colors.yellow)
-- BUNDLED CABLE "OUTPUTS"
local makeWood = redstone.testBundledInput(CablePort, colors.brown)
local makeCoal = redstone.testBundledInput(CablePort, colors.black)
local makeCoke = redstone.testBundledInput(CablePort, colors.gray)
local loadwood = redstone.testBundledInput(CablePort, colors.orange)
local loadCoal = redstone.testBundledInput(CablePort, colors.blue)
local loadCoke = redstone.testBundledInput(CablePort, colors.lightBlue)
-- EVENTS
os.pullEvent("redstone")
-- REBOOT BUTTON CODE
if rebootSystemButton == true then
--REBOOT
term.clear()
mon.clear()
os.reboot()
-- RESET BUTTON CODE
elseif resetCounterButton == true then
-- SETS THE SAVE FILE FOR COUNTER BACK TO ZERO
cokecount = 0
-- CLEAR & INITIALIZE TERMINAL SCREEN
term.clear()
term.setCursorPos(1,1)
print "Loader Control System v1.0"
term.setCursorPos(1,3)
print "System: Online"
-- CLEAR & INITIALIZE MONITOR SCREEN (TOP)
local mon = peripheral.wrap("top")
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(3,1)
mon.write "Loader Control System v1.0"
mon.setCursorPos(3,3)
mon.write "System: Online"
-- PRINT CURRENT COALCOKE INVENTORY COUNT TO TERMINAL SCREEN
term.setCursorPos(1,5)
print("Coalcoke Inventory:", cokecount)
-- PRINT CURRENT COALCOKE INVENTORY COUNT TO MONITOR SCREEN (TOP)
mon.setCursorPos(3,5)
mon.write "Coalcoke Inventory:"
mon.setCursorPos(22,5)
mon.write(tostring(cokecount))
-- COUNT COALCOKE
term.setCursorPos(20,5)
print(cokecount)
mon.setCursorPos(22,5)
mon.write(tostring(cokecount))
-- DUPLICATE & LOAD COKE INTO CHESTS (OUTPUT)
elseif cokecount <= 512 then
for i = 1, 6400 do
pulse(CablePort, colors.gray, .500) -- make a .5-second pulse and make COKE on Gray wire
sleep(0.5)
os.loadAPI("ocs/apis/sensor")
local chestCokeCount = sensor.wrap("left")
--# reset chest/item count
cokecount = 0
--# get target details for X, Y, Z location.
details = chestCokeCount.getTargetDetails("-6,0,-1")
--# iterate the list of slots.
for i = 1, #details.Slots do
if details.Slots[i].Size then
--# add items to count
cokecount = cokecount + details.Slots[i].Size
term.setCursorPos(1,5)
term.clearLine()
term.setCursorPos(1,5)
print("Coalcoke Inventory:", cokecount)
mon.setCursorPos(1,5)
mon.clearLine()
mon.setCursorPos(3,5)
mon.write "Coalcoke Inventory:"
mon.setCursorPos(22,5)
mon.write(tostring(cokecount))
end
end
end
end
end