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

Run Co-Routine With Mouse Click Event

Started by CraftedCart, 13 August 2013 - 05:03 AM
CraftedCart #1
Posted 13 August 2013 - 07:03 AM
How would I use so something like co-routines or parallels.waitForAny() with a mouse click event

event, button, x, y = os.pullEvent("mouse_click")

if y == 18 then
   --do stuff
end

Since os.pullevent() calls coroutine.yeild(), how would I have 2 functions, one of them using the mouse click event, run at the same time?

EDIT: The other function would be read() [For a login screen with shutdown and restart buttons]

Making an OS called CraftedOS which I would like to use this help for
LBPHacker #2
Posted 13 August 2013 - 07:10 AM
Again? I understood you have one function which processes a mouse_click event, but what would the other do?
MR_nesquick #3
Posted 13 August 2013 - 08:58 AM
you can take a look at http://www.computercraft.info/forums2/index.php?/topic/11142-ospullevent-with-timeout/
CraftedCart #4
Posted 13 August 2013 - 12:21 PM

Thanks for that, will probably be helpful but I forgot to mention that the other function will be running read() so I don't think that it will help

[EDIT] would be helpful for some buttons with a clock that auto updates
immibis #5
Posted 14 August 2013 - 04:04 AM
Put the mouse click code in a function, and the read() code in a function, and use parallel.waitForAny(mouseClickFunctionName, readFunctionName).
It will run both of them at the same time until either returns.
CraftedCart #6
Posted 15 August 2013 - 08:27 AM
Put the mouse click code in a function, and the read() code in a function, and use parallel.waitForAny(mouseClickFunctionName, readFunctionName).
It will run both of them at the same time until either returns.

Thanks, I think I have tried this but it didn't work, I'll just look over my code
LordIkol #7
Posted 15 August 2013 - 08:34 AM
maybe post your code then we can give you better help :)/>
CraftedCart #8
Posted 17 August 2013 - 10:36 AM
maybe post your code then we can give you better help :)/>/>
Hopefully I will soon, it's just I reworte the code to say to the user "Use ctrl+S to shutdown"
Hopefully shouldn't take too long to write it back in