This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
My second brick wall...
adrius42 last edited by
Timing and Queuing
Either my code ends a game and opens a Game Over menu before an Action sequence was completed.eg pearly removing the last cards from the screen.
Or fast user interactions are so fast that calls to an object ( that removes pairs of cards for example) are too frequent and cause errors, that are not seen when user acts more slowly.
I am confident there are techniques that I need to find in the documentation... pointers to the right pages please, for
1 Method for allowing an action to complete, before Game Over
2 Method for queuing calls to a block of code
Thanks in anticipation
Part of my problem is 1 I don’t know the keywords to search for
And 2 the current document search is pretty unforgiving.
I often find myself backing out to Google to try and explore a Python concept.
bennr01 last edited by bennr01
Take a look at
threading.Event, which can be used to pause a thread until a flag is set.
I dont know if this works with the
scene-module, but it may be what you are looking for.
Theoretically, you could do something like the following:
- have a attribute/global
- when the action is started, call
- when the is completed, call
- when the game-over condition is met, call
myevent.wait()before showing the screen.
This should allow you to wait for one action to complete. For more than one action in parallel, take a look at
This is a bit more complicated, but do you realy need to queue those calls?
If every call is in a seperate thread, you could use a
threading.Lock()to ensure the action is only executed once in paralell.
If they are not seperate threads, you could use a
queue.Queueor a simple
list, append the call-specific
kwargs, then have a loop taking the first element and processing the call.
I hope this helps you a bit :)
Edit: As @JonB pointed out
scenedoes not use individual threads, thus this answer is mostly invalid. You could still create your own
queue.Queuefor queuing calls.
- have a attribute/global
JonB last edited by
will stop pending actions on a node. I wouldnt try to use any threading methods in scene; for one thing, I think scenes are all a single thread -- an update method gets called once per frame, and actions execute one cycle per frame. You dont want to block in any scene methods. Actions just get executed a step at a time before the next update is called.