WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Simple Programming Question (https://forum.worldviz.com/showthread.php?t=4208)

new_horizon 04-18-2012 08:17 AM

Simple Programming Question
 
Hi All,

Forgive my ignorance, but I am writing a program where I have a set of commands that occur for a given number of trials (for in in range (0, No_trials)).

I wish to have another event that only occurs every three trials (i.e. when i is 3, 6, 9 etc) - can anyone tell me how I would express this in Python?

Many thanks

Mark

farshizzo 04-18-2012 09:57 AM

Are you using the viztask module to run your trials? Either way, here is some code that shows how you can detect every third trial:
Code:

import viz
import viztask
viz.go()

NUM_TRIALS = 10

def runTrial():

        yield viztask.waitTime(1.0)



def runExperiment():

        for i in range(NUM_TRIALS):

                if i % 3 == 2:
                        print 'Special event for every third trial'

                yield runTrial()

                print 'Finished trial',i+1

viztask.schedule( runExperiment() )



All times are GMT -7. The time now is 04:25 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC