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

Problems With "parallel.waitforany()"

Started by 1234tree4321, 06 October 2013 - 07:17 AM
1234tree4321 #1
Posted 06 October 2013 - 09:17 AM
I've tried to run 2 functions at once via "parallel.waitForAny()", but the first function goes further and does not stop…

Example :


term.clear()

function f1()
  term.setCursorPos(1,1)
  x = io.read()
  print("Got keyboard input!")
end

function f2()
  term.setCursorPos(1,19)
  write("Cancel")
  term.setCursorPos(1,1)

  while true do
	local event, button, X, Y = os.pullEvent("mouse_click")
  
	if X <= 10 and Y == 19 and button == 1 then
	  print("\nCanceled")
	  break
	end
  end
end

parallel.waitForAny(f1,f2)

print("\nPress any key to continue!")

local event, key = os.pullEvent("key")
...

The Problem is that f1() still is waiting for Input after I've clicked "Cancel".

How i can fix this? Need Answers! :-)
LBPHacker #2
Posted 06 October 2013 - 09:58 AM
Since that's sort of impossible, I have to ask, how do you know that f1 is still waiting?
theoriginalbit #3
Posted 06 October 2013 - 10:03 AM
Since that's sort of impossible, I have to ask, how do you know that f1 is still waiting?
I would assume that OP thinks this because there is still the cursor blinking due to the fact that read never gets to run term.setCursorBlink(false) as it is terminated while reading and never breaks the loop

btw OP, there is your answer too :P/>
1234tree4321 #4
Posted 06 October 2013 - 04:04 PM
Since that's sort of impossible, I have to ask, how do you know that f1 is still waiting?
I would assume that OP thinks this because there is still the cursor blinking due to the fact that read never gets to run term.setCursorBlink(false) as it is terminated while reading and never breaks the loop

btw OP, there is your answer too :P/>


(Sorry, i am German :S)

So term.setCursorBlink(false) breaks f1()?
ElvishJerricco #5
Posted 06 October 2013 - 06:11 PM
So term.setCursorBlink(false) breaks f1()?

Nope. f1 should have already broken. But it broke before getting the change to tell the cursor to stop blinking.
1234tree4321 #6
Posted 07 October 2013 - 09:40 AM
So term.setCursorBlink(false) breaks f1()?

Nope. f1 should have already broken. But it broke before getting the change to tell the cursor to stop blinking.

Allright, Thank you guys! :-)