So I want to have a function like this:
wait_for_input(time)
Where if you push a button within that amount of time it returns true, otherwise when the timer is up it returns false. Is there any way I can do this? If it helps, I am using hump.timer in my game.
Wait for input for a certain amount of time?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Wait for input for a certain amount of time?
No, because such a function would suspend execution, thus stopping the game completely, ignoring all input and drawing nothing to the screen.
You'll want to rework your control flow to make it work. Probably use hump.timer.add(amount_of_time, cancelfunction).
You'll want to rework your control flow to make it work. Probably use hump.timer.add(amount_of_time, cancelfunction).
Help us help you: attach a .love.
- rhezalouis
- Party member
- Posts: 100
- Joined: Mon Dec 07, 2009 10:27 am
- Location: Indonesia
- Contact:
[Response]ButtonWaiter Prototype
Hi tesselode,
Check this out P.S. Anyway, if you still want to implement this requirement using functions, you could create a function that returns a newly defined waiting_for_input function and its upvalues. There might be some difficulties to control the upvalues as the load, update, draw and pressedkey-check are done in different callbacks. Be careful it might end up being un-tabled version of that object/table implementation ; I guess the logic for functions should be quite different from tables.
To do that, you need to track the time that has passed and check the pressed keys. I guess the most easy and flexible way to manage these variables are by using an object/prototype (in Lua, an object is simply a table ). In the attached LÖVE file, you could see a from-scratch sample of such object. The object buttonWaiter didn't return true or false as you requested though, instead, it receives a callback function that would be called if the key-you're-waiting-for is pressed when the object is in wait (isActive). In the sample callback (shout()), you could see that it toggles a boolean flag that could be used to substitute the returned value you mentioned .Tesselode wrote:if you push a button within that amount of time it returns true, otherwise when the timer is up it returns false.
Check this out P.S. Anyway, if you still want to implement this requirement using functions, you could create a function that returns a newly defined waiting_for_input function and its upvalues. There might be some difficulties to control the upvalues as the load, update, draw and pressedkey-check are done in different callbacks. Be careful it might end up being un-tabled version of that object/table implementation ; I guess the logic for functions should be quite different from tables.
Last edited by rhezalouis on Sun Dec 18, 2011 6:46 am, edited 2 times in total.
Aargh, I am wasting my posts! My citizenshiiiip...
Re: Wait for input for a certain amount of time?
Don't worry, I already figured out something.
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 3 guests