Posted 14 April 2012 - 01:50 PM
I've been playing around with the idea of catching input and running a timer at the same time.
My first idea was something like this:
Problem is my updateTimer method required moving the terminal cursor- that may not be why but io.read just didn't work.
Next idea was to just capture events, and convert the keycodes I receive into a string that made up my query:
The issue here was the string.char() method has a wildly differing definition of keys to the os.pullEvent method.
Neither method worked but I think both should. They need to be adapted better to the development environment.
Could anyone suggest how either or both can be adapted to work better with the existing API's and Lua framework?
Thanks for reading,
Nitrogen Fingers
My first idea was something like this:
function updateTimer()
os.startTimer(1)
os.pullEvent("timer")
--Code goes here
end
function parseInput()
local input = io.read()
--Code goes here
end
while true do parallel.waitForAny(updateTimer, parseInput) end
Problem is my updateTimer method required moving the terminal cursor- that may not be why but io.read just didn't work.
Next idea was to just capture events, and convert the keycodes I receive into a string that made up my query:
while true do
local id,key = os.pullEvent()
if id=="timer" then updateTimer()
else
if key==28 then parseInput(input)
else input = input..string.char(key)
end
end
The issue here was the string.char() method has a wildly differing definition of keys to the os.pullEvent method.
Neither method worked but I think both should. They need to be adapted better to the development environment.
Could anyone suggest how either or both can be adapted to work better with the existing API's and Lua framework?
Thanks for reading,
Nitrogen Fingers