Posted 15 December 2013 - 03:43 PM
So, i made this simple little program to manage my tree farm. I've tried VERY many ways to do this but parallel (api) always messes it up..
Basically it only does the function that is first so if i write
Here's the code for the whole program
I hope someone can find a fix for this
Basically it only does the function that is first so if i write
parallel.waitForAll(timer(), click())
It would only run the timer function and if i do the other way around
parallel.waitForAll(click(),timer())
it only runs the click function.Here's the code for the whole program
mouseHeight = 0
mouseWidth = 0
onOff = true
function printMonitor(state, number, max)
monitor.setCursorPos(1,1)
monitor.setTextScale(1)
monitor.write(state.. " ".. number)
monitor.setCursorPos(1,2)
monitor.write("/".. max)
end
function timer()
local maxOn = 60
local maxOff = 270
while true do
for i = 1, maxOn do
if onOff == true then
rs.setOutput("right", true)
sleep(0.5)
printMonitor("On",i,maxOn)
else
repeat
monitor.setCursorPos(1,1)
monitor.setTextScale(2)
monitor.write("OFF")
until onOff == true
end
end
for i = 1, maxOff do
if onOff == true then
rs.setOutput("right", false)
sleep(0.5)
printMonitor("Off", i, maxOff)
else
repeat
monitor.setCursorPos(1,1)
monitor.setTextScale(2)
monitor.write("OFF")
until onOff == true
end
end
monitor.setCursorPos(1,1)
monitor.write("OFF")
end
end
function click()
while true do
event, p1, p2, p3 = os.pullEvent()
if event == "monitor_touch" then
mouseWidth = p2
mouseHeight = p3
if mouseWidth >15 and mouseWidth < 18 and mouseHeight == 2 then
onOff = false
print("OOPS")
end
if mouseWidth >12 and mouseWidth < 18 and mouseHeight == 4 then
onOff = true
print("off")
end
end
end
end
monitor = peripheral.wrap("top")
monitor.setBackgroundColour(colours.lime)
monitor.setCursorPos(12,2)
monitor.write(" ON ")
monitor.setCursorPos(12,4)
monitor.write(" OFF ")
monitor.setBackgroundColour(colours.black)
parallel.waitForAll(timer(),click())
I hope someone can find a fix for this
Edited by