188 posts
Location
Germany
Posted 03 November 2016 - 06:27 PM
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.
3057 posts
Location
United States of America
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.
8543 posts
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.
188 posts
Location
Germany
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.
1610 posts
Posted 04 November 2016 - 10:20 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.
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
7083 posts
Location
Tasmania (AU)
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".
96 posts
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)