Is there a possiblity, to test for a event without waiting? os.pullEvent waits for a event and then the code continuing, but I want to ask for a event without stoping the code. If there no event at this time, it could be return nil or something else.
Test for a event without waiting
Started by Wilma456, Nov 03 2016 06:27 PM
6 replies to this topic
#1
Posted 03 November 2016 - 06:27 PM
#2
Posted 03 November 2016 - 06:40 PM
Queue a dummy event first. Though I'm not sure why you would need to do this; remember that only one CC computer executes at a time.
#3
Posted 03 November 2016 - 06:47 PM
Why do you think you need to do this? There's probably a better way to accomplish what you're ultimately trying to do.
#4
Posted 04 November 2016 - 06:08 PM
I need this for a game engine, who every object has his own script. The game should not stop while one object wait for input.
#5
Posted 04 November 2016 - 10:20 PM
Wilma456, on 04 November 2016 - 06:08 PM, said:
I need this for a game engine, who every object has his own script. The game should not stop while one object wait for input.
Using coroutines/the parallel API would be a much better choice here, but if you really want to do it this way you can use code like this:
os.queueEvent("dummy")
local e = {os.pullEvent()}
while e[1] ~= "dummy" do
-- process events
-- eg e[1] might be "char", e[2] might be "b", etc
e = {os.pullEvent()}
end
#6
Posted 05 November 2016 - 12:46 AM
It sounds like os.startTimer() is much more suitable than os.queueEvent(), in this case. Ultimately, no game needs a frame rate of "unlimited".
#7
Posted 13 November 2016 - 02:11 PM
You could use parallel or coroutine, for instance
function waitForKey()
e,k = os.pullEvent("key")
if k == 42 then
print("Enter!")
else
print("Not enter!")
end
end
function runCode()
while true do
term.setTextColor(colors.lime)
print(math.random(1,10000000))
term.setTextColor(colors.white)
end
end
parallel.waitForAny(runCode,waitForKey)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











