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.


    Action.repeat() won't repeat.

    Pythonista
    action repeat scene
    4
    12
    8750
    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.
    • Kamozo
      Kamozo last edited by Kamozo

      Hello, why won't "repmo" repeat itself?
      I would like the action to continuously run after "phase_1", yet it only runs once. How do I fix this? Thank you.

              up = A.move_to(self.size.w/2, 350, 9,TIMING_EASE_BACK_OUT)	
      		mo = A.move_to(random.randrange(100,924),random.randrange(300,700), 2, TIMING_EASE_BACK_IN_OUT)
      		repmo = A.repeat(mo, -1)
      		phase_1 = A.sequence(stationary, up) #stationary appears earlier
      		self.boss.run_action(A.sequence(phase_1, repmo)) 
      

      This is only a snippet of code, I'm just highlighting the bits that need looking at. For example, although the code doesn't specify, A = Action.

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

        The action does repeat, but the random coordinates are only calculated once, so each repetition moves to the same point (which has the same effect as if it wouldn't repeat at all).

        If you want new random coordinates with every repetition, you'd need to use a custom call action.

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

          Ahh, I understand that, thanks.
          I'll have to do some more reading now, because the call function confuses me, it doesn't take much code does it? Could you give an example of how I would do it, if that isn't too much to ask?
          But anyway, thanks, I'll look into it.

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

            Something like this should work:

            up = A.move_to(self.size.w/2, 350, 9, TIMING_EASE_BACK_OUT)
            d = 2.0 # duration
            # Inline function for the call action:
            def move_random():
              x, y = random.randrange(100,924), random.randrange(300,700)
              self.boss.run_action(A.move_to(x, y, d))
            # The call action doesn't wait until the move action finishes, so add a wait action for that:
            repmo = A.repeat(A.sequence(A.call(move_random), A.wait(d)), -1))
            phase_1 = A.sequence(stationary, up)
            mo = A.move_to(, 2, TIMING_EASE_BACK_IN_OUT)
            self.boss.run_action(A.sequence(phase_1, repmo))
            

            (I actually used a slightly simpler example for testing, so there might be some typos here)

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

              Wow, thank you, that helps me a lot.

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

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • omz
                  omz last edited by

                  Sorry, there's a closing parenthesis too much, it should be:

                  repmo = A.repeat(A.sequence(A.call(move_random), A.wait(d)), -1)
                  
                  Webmaster4o 1 Reply Last reply Reply Quote 0
                  • Kamozo
                    Kamozo last edited by

                    Oh yeah, I'm not sure how I didn't notice that.
                    Where does the code you've provided fit into mine?

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

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • Kamozo
                        Kamozo last edited by

                        Nevermind, I've figured it.
                        Thanks for all your help.

                        1 Reply Last reply Reply Quote 0
                        • Webmaster4o
                          Webmaster4o @omz last edited by

                          @omz said:

                          Sorry, there's a closing parenthesis too much, it should be:

                          It sounds much less awkward to an American if you say "there's one too many closing parentheses," but not a big deal. Just putting it out there

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

                            I hadn't realised the A.call() thing existed - loads of possibilities for animations!

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