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

Simple LUA Timing Question

Started by fatboychummy, 16 October 2016 - 08:52 PM
fatboychummy #1
Posted 16 October 2016 - 10:52 PM
Alright, so in a while true do block, if I have it set up like so….




while true do

  function1()
  function2()

end
will this run function 1 first until it's finished, then 2? Or will it run both at once?
Edited on 16 October 2016 - 08:52 PM
H4X0RZ #2
Posted 16 October 2016 - 10:54 PM
It will run function1 first. Then function2.

There is no true simultaneous execution in CC. You can only emulate it using coroutines and/or the parallel API.

Try this:

function function1_wrapper()
  while true do
	function1()
  end
end

function function2_wrapper()
  while true do
	function2()
  end
end

parallel.waitForAny(function1_wrapper, function2_wrapper)
Edited on 16 October 2016 - 08:55 PM