I’ve been searching for a functionality similar to this, and when I think I’ve finally found it, it doesn’t quite work like I perceived it to. I’ve done searches for it but I can’t find any solid documentation on what it does. Can anyone help me out?
bge.logic.NextFrame() should theoretically bump the render to the next frame, allowing you to put it inside a loop manipulating object location for instance. It would make things so much easier if it allowed the next frame to render while running a script, but it doesn’t seem to work like that.
I am the author of that patch, and its reason is simple: grabbing mainloop control in Python, to support parallel systems of game logic, independent of logic bricks.
It was never meant to run inside a logic brick, this may easily lead to infinite recursion. To prevent this, bge.logic.NextFrame() will do nothing unless mainloop control has been grabbed by Python.
If you want to suspend your Python controller script until after the next frame is rendered, you should do it differently: storing a Python variable (e.g. “progress”) in a global variable or a dict, and reading it back in on the next frame, when the logic brick system activates your Python controller again.
Don’t use a loop for this.
At present you create a custom property on the scene (or is it world) called main with a string value of the name of the python file. I’ve written a patch so that you’d subclass bge.types.KX_PythonLogicLoop and define it in the UI, but it needs further work to fix Blender
That means it’s working. You’ve given the Python script full control, meaning it tells the game what to do and when (although, in reality it can’t exclude specific components of the nextFrame call, so it’s not fully in control). So, you’ve simply run one frame and then exit. If you want to run more than one frame, use a while loop. However, I’m not sure how that would work in terms of timing or exiting, so give it a try.
i have got the mechanism, so basically all bge run inside the “while”.
but not clear if it can give also some advantage , maybe is usable for “massive subclassing” ??(ie all obj created get a new function for example , avoiding try/except, if not “init” in own and other annoyng stuff?)
this is the code that work:
press ESC to exit
t = time.clock()
tMax = t+5.0
FPS = 60.0
frameTime = 1 / FPS
LOOP = True
while LOOP :
t1 = time.clock()
if bge.logic.keyboard.events[bge.events.ESCKEY] :
LOOP = False
obs = [i for i in bge.logic.getCurrentScene().objects if "prop" in i]
for i in obs:
i.worldPosition.x += random.uniform(-1,1)
i.worldPosition.y += random.uniform(-1,1)
i.worldPosition.z += random.uniform(-1,1)
t2 = time.clock()
#timeForSleep = t2 - t1
#if timeForSleep > 0.0:
time.sleep(0.016) #...hem...is calculable...