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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Zamp
Prole
Posts: 14
Joined: Sun Oct 07, 2012 1:30 pm

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

Post 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
Last edited by Zamp on Mon Feb 10, 2014 12:55 pm, edited 1 time in total.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Using io.read without blocking the game ?

Post 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.
Zamp
Prole
Posts: 14
Joined: Sun Oct 07, 2012 1:30 pm

Re: Using io.read without blocking the game ?

Post by Zamp »

Cool, I will try that. Thanks :D

Edit: It works perfectly, thanks again !
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests