Posted 25 June 2013 - 10:40 AM
I am trying to have a program that will repeat a process based on a previously stored event value. For example, in a game if you moved a joystick to the left, the player would start and continue moving left until a new input was received which changed direction. Now the player would move in that direction until a new input, etc…
The problem is that the os.pullEvent() halts the program and waits for a new input. In the example below, there is only one Tick. When input is received, the program will Tock then Tick.
That is needed is a Tick, Tick, Tick… until an input is received. Then a Tock & repeat ticks, etc.
I read the forums and about Lua online. Is there an event handler that will not halt the program? Or - a completely different way of accomplishing this task?
thanks-
-Snails
The problem is that the os.pullEvent() halts the program and waits for a new input. In the example below, there is only one Tick. When input is received, the program will Tock then Tick.
That is needed is a Tick, Tick, Tick… until an input is received. Then a Tock & repeat ticks, etc.
I read the forums and about Lua online. Is there an event handler that will not halt the program? Or - a completely different way of accomplishing this task?
--[[ Main loop ]]
while true do
--[[ Clear events ]]
sleep(0)
--[[ Repeat until button is pressed... ]]
repeat
--[[ Do work... ]]
repeatedTick()
--[[ CAPTURE EVENT ]]
event,side,x,y = os.pullEvent()
--[[ Repeat... ]]
until event == "monitor_touch"
--[[ New work and settings based on event ]]
tock(x,y)
--[[ Repeat entire process... ]]
end
thanks-
-Snails