WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 02-07-2016, 10:08 AM
jelly jelly is offline
Member
 
Join Date: Feb 2016
Posts: 38
Hello again!

I got the lower window exchange to work. That alone taught me some things about global variables and how to think about those TexQuads. Now on to the next problem: Exchanging the picture in the lower window 7 out of 10 times with one picture and 3 times with another (randomly).

I tried the list strategy, as suggested by Erikvdb, I've consulted all my resources, and I managed to implement it. However, the problem is that sometimes it shows the picture C 3 random times (as it should), other times, only 1 or 2 times. Almost as if it's randomly picking from the list 10 times. However, I want it to go through the entire list once. I am wondering if my list implementation is correct? Maybe I should not put several identical elements in a list? Or it's a problem regarding the implementation inside the "while loop"

I tried to simplify the code and create this as a separate script with the simplest form of the issue, as suggested by Jeff. Rather than code debugging I am hoping that someone might link me to a relevant example of a list within a loop. Obviously I am lacking the logic behind it especially when things get nested.


Code:
## Import Vizard modules ##

import viz 																														
import viztask							
import random							

#Start Vizard:															
viz.go()

## STIMULI ##

#pictures
pictureA = viz.add('picA.jpg')
default = viz.add('default.png')

#sound
cue = viz.addAudio('dong.wav')

#list (7 times picture B and 3 times picture C)
pictureList = ['picB.png', 'picB.png', 'picB.png', 'picB.png', 'picB.png', 'picB.png', 'picC.png', 'picC.png', 'picC.png']


#Make a screen window:
screen1 = viz.addTexQuad(size=0.5)            
screen1.setPosition([0,2.1,1.3])
screen1.setSize([0.4, 0.4])

#Make a second screen window:
screen2 = viz.addTexQuad(size=0.5)            
screen2.setPosition([0,1.6,1.3])
screen2.setSize([0.4, 0.4])

## TASK##

def task():
	screen1.texture(pictureA)
	screen2.texture(default)

	def playCueLoop():  # default picture is shown in lower window + 10 times, at randomly intersperced intervals, a sound beep plays & each time that happens, the lower window replaces the default picture randomly with 7 times picB and 3 times pic C
		count = 0
		while count < 10:
			count += 1
			cue.play()
			pictureIndex = 0
			random.shuffle(pictureList)
			picture = viz.add(pictureList[pictureIndex])
			screen2.texture(picture)
			pictureIndex += 1
			yield viztask.waitTime(0.5)
			screen2.texture(default)
			yield viztask.waitTime(0)
			yield viztask.waitTime(random.randrange(1,4))	
	viztask.schedule (playCueLoop())

viztask.schedule(task())
My only resource is a huge code with one list example (but there is no loop) - this is just a snippet:

Code:
photoList = ['A1.jpg','A2.jpg','A3.jpg','A4.jpg','A5.jpg','A6.jpg','A7.jpg','A8.jpg','A9.jpg','A10.jpg']
random.shuffle(photoList)

photo = viz.add('Pictures\\' + photoList[photoIndex])
photoFrame.texture(photo)
photoIndex += 1
I would be very greatful for any help or pointers!

P.S. I know Erikvdb suggested in another thread to stop the sound as well, however I left that out for now, to simplify the code
Reply With Quote
 

Tags
condition, loop, picture, sound

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
playing a sound multiple times at different timings jelly Vizard 3 02-04-2016 03:39 AM


All times are GMT -7. The time now is 11:05 AM.


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