Hi all,
I have been using Pythonista to learn Python for a few months (I'm new to coding) and have been exploring the Scene module since the recent update.
I've made a grid-based game in which players make a white path across the grid, and if successful, all the squares making up the path turn green.
I use a function (see below) to recursively check for success (not sure if this is the best way or not) by checking the neighbours of each tile as the "path"
progresses through the grid.
It worked well until introducing time.sleep() as a very brief delay in order to "animate" the progress of the squares turning green. Now it crashes Pythonista but not in a predictable way, though it does seem to be when the function is running. The function is decorated with @ui.in_background.
I'm just looking for any advice on how to improve my code to prevent this, or whether other people have had a similar problem.
I can post the whole code if needed or if anyone interested.
@ui.in_background
def go(self, start_square):
try:
self.green_list.remove(start_square)
except:
pass
for square in start_square.white_neighbours(self.squares):
self.green_list.append(square)
square.run_action(go_action)
square.state = 3
square.color = color4
sleep(0.004)
self.go(square)
if len(self.green_list) == 0:
sleep(0.004)
self.check_win()