self.run_action(A.wait(1)) not working
Louise last edited by Louise
I’m new to Pythonista & a relative beginner to Python / coding in general.
I’m trying to adapt a Reversi game I made with Pygame to use Pythonista Scene module instead. I want to pause for a second before the computer makes its move, so you can see the results of your move. I put
as the first line in the function that makes the computer’s move, but it is not pausing, any idea what I’m doing wrong?
JonB last edited by
Any separate run_action calls all get called in parallel, essentially. So if you have a sequence of actions, one of which is a wait, you need to create an
Action.sequencethat captures the actions in order.
stephen last edited by stephen
Here is a snippet from the Space Escape Demo I posted to help with this sort of thing. It's got a lot going on but it shows a good amount of Animation functionality.
def ForceField(self, speed, repeat=-1, t=TIMING_ELASTIC_IN_OUT): def color_to(node, progress): node.color='#09dfff' if random.random() < 0.5 else '#0016ff' fade= scale= rotate= for x in range(100): val=random.random() if val < 0.5: val = 0.5 mod=random.random() fade.append(a.fade_to(val-0.4, speed, t)) fade.append(a.call(color_to, 0.1)) if val < 0.6: val = 0.8 rotate.append(a.rotate_by(val*5, speed, t)) scale.append(a.scale_y_to(val, speed, t)) scale.append(a.scale_x_to(val, speed, t)) self.node.run_action( a.repeat( a.group( a.sequence(fade), a.sequence(scale), a.sequence(rotate)), repeat))
stephen last edited by
i do believe that wait cannot be called by itself. you must call a functional action also. but you can do a few things. you cqn use
Action.call(func)and leave it empty, or yu can use call and inside the called function/methos yiu can run the logic needed to end p,ayer tuen or start NPC turn.
alternatively instead of using
run_actionyou can use
time.sleep(1.0)though you might need to run this call on the main thread..
If your also using the
uimodule there is
ui.delay(func, seconds)you wont need to import
uibecause its aleady imported within
sceneand accessible through your
from scene import *
my favorite, but unnecessary, is creating a timer Node subclass and when you need a timer instantiate an instance of it seting duration and reduce time by Delta Time. when finished call a function set at creation.
i hope this helps. let us know if you need any further help buddy!
Louise last edited by
Thank you all for your help.
I have now got it working! I have a variable that holds whether it’s the players turn or computer’s turn. As all the functions are in if statements dependant on this variable (like a game_state variable) I set it to ‘wait’ immediately before I want my wait & then my action sequence calls a function to set it to ‘computer’ after the wait.
Thanks again for the extra info on how wait works - don’t think I would have got there on my own!
stephen last edited by