PDA

View Full Version : Newbie - Trouble using loops


lawry2
07-30-2014, 11:49 AM
Hi all,

I'm new to using Vizard and am having difficulty using loops. My issue is that when I use a loop, it blocks the environment from being rendered. I thought that this was OK as I was using the same method I saw in the Vizard documentation.


import viz
import viztask

env = viz.add('../models/environment.OSGB')

viz.go()

def run():

while True:
# Something simple
print viz.MainView.getPosition()
print viz.MainView.getEuler()

viztask.schedule(run())


What I get here is just a black window. The model is never seen but the output window shows the camera Euler and position. I'm aware that the loop is blocking but how do I get around this?

Jeff
07-30-2014, 01:35 PM
Functions scheduled with viztask must contain a yield command. The following should work:

import viz
import viztask

env = viz.add('dojo.osgb')

viz.go()

def run():

while True:
# Something simple
yield viztask.waitTime(1)
print viz.MainView.getPosition()
print viz.MainView.getEuler()

viztask.schedule(run())

lawry2
07-30-2014, 01:38 PM
Thanks for the quick reply.

Yep, that worked. I must ask though, why is this?

Using what you said, I have put the print statements in another function and I call that using a yield statement.

Jeff
07-30-2014, 01:51 PM
Vizard's task functions are implemented using Python generators which use yield statements.