I was curious as to if you could use read() or os.pullEvent() with an added argument to only accept input for a specified amount of time. An example as to where this might be useful would be:
If you had a menu with a moving background or image (like a character moving) and you wanted this character to change positions every half second but you still wanted to be accepting input at the same or roughly the same time. So the user could press the arrow keys to navigate the menu whilst the background is shifting through its phases.
The reason read() or os.pullEvent() won't work for this is because if the user is thinking about his/her decision on what option to pick, the background will lay motionless until a key is pressed to trigger the background change.
Any ideas?
Thanks in advance, PaymentOption.
[Question] Input Sleeping(Yielding)
Started by Grim Reaper, May 16 2012 01:37 AM
3 replies to this topic
#1
Posted 16 May 2012 - 01:37 AM
#2
Posted 16 May 2012 - 01:52 AM
Use os.pullEvent() with a timer. So something like this.
os.startTimer(5) local evt, p1, p2 == os.pullEvent() if evt == "key" then do key stuff elseif evt == "timer" and p1 == "timer" then do timer stuff end
#3
Posted 16 May 2012 - 02:49 AM
Thank you!
#4
Posted 16 May 2012 - 05:00 PM
Or use the parallel API:
local function drawBackground()
while true do
-- draw the background or whatever
sleep(1) -- to let the other function work
end
end
local function getInput()
while true do
local s = read()
-- do something with the input
end
end
parallel.waitForAny(getInput, drawBackGround)
I would work almost the same, choose what you think it's better for what you need.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











