Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Iterating through a list of objects

Hi there,

I am trying to iterate through a list of objects, what I want to do is if only 1 object in the list returns true, the program should continue until all the other objects return True.

Here is my update method:
Code
def next_frame(self):
        global finish
        if(Clock.time%(random.randrange(1,60, 2))==0):
            self.set_frame(self.frame + 1)
        if(self.done()):
            finish = True


Here is my method for returning a boolean value:
Code
def done(self):
        global finish
        if((self.frame == (self.grid_s[0]*self.grid_s[1])-1)):
            #finish = True
            return True
        else:
            return False
At the current moment what this does is, when I run the program I initialise a few objects so they are run, but after my first object in the list returns True, all my other objects stops what they are doing and my program stops working. How can I make changes so that the program will stop only after all the objects have returned True. Please let me know if you need to see more of my code, thanks!
Without more code I can't say for sure but I think what you're doing is setting a global variable "finish" to the result of this condition
PHP Code

<?php 
self
.frame == (self.grid_s[0]*self.grid_s[1])-1) 

So if this is true then finish will also be set to true and i presume finish is the control variable that stops the main loop for something.
So I guess change the condition so that it fits your goal, I dont really know how tho since I don't really understand without any context.
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
(Feb 13, 2020 11:09 AM)lockhead Wrote:  Without more code I can't say for sure but I think what you're doing is setting a global variable "finish" to the result of this condition
PHP Code

<?php 
self
.frame == (self.grid_s[0]*self.grid_s[1])-1) 

So if this is true then finish will also be set to true and i presume finish is the control variable that stops the main loop for something.
So I guess change the condition so that it fits your goal, I dont really know how tho since I don't really understand without any context.

A friend of mine was able to help me yesterday and it finally works all I needed was to remove the explosions from the list after it was done. My god the solution was so simple.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by PsychoJul 3, 2021 11:15 PM 24 1,973 Jul 3, 2021 11:15 PM
Last Post: Lookdadon
[Python] by simmerMay 26, 2021 10:25 PM 2 119 May 26, 2021 10:25 PM
Last Post: simmer
[Python] by SympthFeb 4, 2020 07:54 AM 6 383 Feb 4, 2020 07:54 AM
Last Post: Nikix