omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    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...

    Pythonista
    3
    3
    1840
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • adrius42
      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—

      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.

      1 Reply Last reply Reply Quote 0
      • bennr01
        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:

        For 1:

        • have a attribute/global myevent
        • when the action is started, call myevent.set()
        • when the is completed, call myevetn.clear()
        • 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 threading.Semaphore and threading.BoundedSemaphore.

        For 2:
        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.Queue or a simple list, append the call-specific args and 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 scene does not use individual threads, thus this answer is mostly invalid. You could still create your own threading.Thread with a queue.Queue for queuing calls.

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          http://omz-software.com/pythonista/docs/ios/scene.html#scene.Node.remove_all_actions
          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.

          1 Reply Last reply Reply Quote 2
          • First post
            Last post
          Powered by NodeBB Forums | Contributors