This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
allquan's profile picture

Button and refresh tank amount

Started by allquan, 23 January 2014 - 03:10 PM
allquan #1
Posted 23 January 2014 - 04:10 PM
Hello I want to make a program, where you have a button on the left side to activate for example a redstone lamp. To make the button is not the problem, but i want to have
on the right side the actual amount of a railcraft tank. So far i only managed to reload the tank info if i click the button. Is there a way to reload the tank info
for example every 5 seconds and making the button clickable at the same time?


I just got an answer from someone. I have to use the paralell api "parallel.waitForAny(function1, function2, …)"

Topic can be closed
Edited on 23 January 2014 - 03:17 PM
CometWolf #2
Posted 23 January 2014 - 04:46 PM
The parallel API is a terrible way of doing that. Read up on os.pullEvent instead
http://computercraft.info/wiki/Os.pullEvent

local updateTimer = os.startTimer(5)
while true do
  local tEvent = {os.pullEvent} -- get events
  if tEvent[1] == "redstone" then --redstone event
    --redstone state has changed, check the button side here
  elseif tEvent[1] == "timer" then --timer event
    if tEvent[2] == updateTimer then
	  --update tank info code here
	  updateTimer = os.startTimer(5)
    end
  end
end