Jump to content




Run Co-Routine With Mouse Click Event

lua computer

  • You cannot reply to this topic
7 replies to this topic

#1 CraftedCart

  • Members
  • 67 posts
  • LocationUnited Kingdom, Earth

Posted 13 August 2013 - 06: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

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 13 August 2013 - 06:10 AM

Again? I understood you have one function which processes a mouse_click event, but what would the other do?

#3 MR_nesquick

  • Members
  • 106 posts
  • LocationNorway

Posted 13 August 2013 - 07:58 AM

you can take a look at http://www.computerc...t-with-timeout/

#4 CraftedCart

  • Members
  • 67 posts
  • LocationUnited Kingdom, Earth

Posted 13 August 2013 - 11:21 AM

View PostMR_nesquick, on 13 August 2013 - 07:58 AM, said:


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

#5 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 14 August 2013 - 03: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.

#6 CraftedCart

  • Members
  • 67 posts
  • LocationUnited Kingdom, Earth

Posted 15 August 2013 - 07:27 AM

View Postimmibis, on 14 August 2013 - 03:04 AM, said:

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

#7 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 15 August 2013 - 07:34 AM

maybe post your code then we can give you better help :)

#8 CraftedCart

  • Members
  • 67 posts
  • LocationUnited Kingdom, Earth

Posted 17 August 2013 - 09:36 AM

View PostLordIkol, on 15 August 2013 - 07:34 AM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users