Page 1 of 1

[Solved] Using io.read without blocking the game ?

Posted: Mon Feb 10, 2014 11:11 am
by Zamp
Hi lövers !

Do you know any way to use io.read() without blocking the game ? I have a console attached to my game and want the player to be able to enter commands in it while playing (to connect to a multiplayer server, change skin, etc... this will avoid me to overcharge my game with a UI layer).

When I use io.read(), it blocks everything and waits for the player input. It's fairly normal when you think about it twice, but how to do this the async way ? (always listen for user's input, and call a callback function when he has entered something)

Thanks guys :D

Re: Using io.read without blocking the game ?

Posted: Mon Feb 10, 2014 11:30 am
by Plu
Use a thread/channel to collect input, and send a message when the user input is completed.

Info on making channels in 0.9.0:
http://love2d.org/forums/viewtopic.php?f=4&t=76670

You can find the thread functions for 0.8.0 on the wiki if you're using that.

Re: Using io.read without blocking the game ?

Posted: Mon Feb 10, 2014 12:15 pm
by Zamp
Cool, I will try that. Thanks :D

Edit: It works perfectly, thanks again !