Execute "for" command in more frames

Guys, I would like your help.
I created a function similar to this:

list = [0, 1, ... 1000]
for x in list:
    #Do something

But it was too heavy to be used in one frame.
Is it possible to use it in several frames until finished?

A for loop should use more frames, a while loop will do it in one frame, if frame passes before while loop is done the while loop suspends/freeze the engine until it’s done with the task given.

You could split it up and use logic.nextFrame() to skip a frame ahead

or you could use for i in range(1000): Would be a tad lighter.

Biggest question will be: What do you want to achieve?
Also are you running it in true pulse? Seems you run it in single pulse.

1 Like

Q the tasks.

class QUEUE:
    def __init__(self, size):
        self.pending=[]; self.size=size;

    def add(self, func, args, kwargs):
        self.pending.append( (func, args, kwargs) );

    def run(self):
        for _ in range(x):
            func, args, kwargs = self.pending.pop(0);
            func(*args, **kwargs);

Usage: you call the add method of a queue like so:

def test(x, y, b=False);
    print(x, y, b)

q.add(test, [1,2], {'b':True});

Then call run at the start of each frame, and that will only execute up to size calls, in the order they were given.

If you need to make sure certain calls are made first, then make a list of queues.

def enqueue(self, func, args=[], kwargs={}, priority=0):
    queues[priority].add(func, args, kwargs);

And then run them in order of priority;

for q in queues:

The func argument can easily be an eval or exec, though that’d be a tad slower it may come in handy in certain cases.

If you’re not used to the *args, **kwargs syntax then google it, it’s a useful thing. Basis is you pass in the non-keyword arguments as a list, and keyword arguments as a sequence of {'argname':argvalue} dictionary; or you pass none if there are no args or it’s a class method that only takes an instance of that class. For example,

class Whatever:
    def some_meth(self):


That will run the method and the instance is passed in implicitly, just as you’d expect. Who would’ve known OOP has it’s uses, eh?

1 Like

Yes, I’m running on a single frame, because I don’t know how to rotate it on more frames.

Wow, complete. I’m going to test and I’ll be back with the result, thank you.

for x in range(100):
    Current = own['List'][own['index']] 
    own['index'] += 1
    if own['index'] >( len(own['List']) - 1):
        own['index'] = 0
1 Like