View Single Post
Old 02-04-2016, 07:47 AM
jelly jelly is offline
Join Date: Feb 2016
Posts: 38
playing sound and displaying picture - condition within loop

Dear all,

I am a programming beginner and I started using Vizard because I am trying to design a little experiment for my studies. Here is what is supposed to happen and below is what I have so far:

The screen should show an upper and a lower window. Each window will receive a simple texture (.png or .jpeg) to display two different pictures. In the upper window, there would be the task instruction and in the lower window, there would be a "default" picture. At the same time, a beep sound will play 10 times at random intervals (from 1 to 4 seconds). What I want: 7 out of ten random times, just as a sound cue plays, the lower screen should change from the default picture to Picture A and 3 out of 10 random times to Picture B.

#Set background colour to white:

taskpic = 'instruction.jpg'
pictureA = 'picA.jpg'
pictureB = 'picB.jpg'
picturedefault = 'default.png'
cue = viz.addAudio('dong.wav')
SoundDuration = cue.getDuration()

import viz 															
import time
import viztask
import random														

def exp(): #this is the function that triggers my experiment

	screen2 = viz.addTexQuad(size=0.5)            #upper screen window
	screen2.setSize([0.4, 0.4])

	screen3 = viz.addTexQuad(size=0.5)            #lower screen window
	screen3.setSize([0.4, 0.4])

	picture_task = viz.add(taskpic)
	defaultpic = viz.add(default)

	screen2.texture(picture_task)			#picture with instruction is added as a texture to upper screen
	screen3.texture(defaultpic)			#default picture is added as a texture to upper screen
	def playCueLoop():
		count = 0
		while count < 10:
			count += 1
			for x in count:
				if x <= 7:
					yield viztask.waitTime(SoundDuration+random.randrange(1,4))
					PicA = viz.add(PictureA)
					yield viztask.waitTime()
				elif x <= 3:
					yield viztask.waitTime(SoundDuration+random.randrange(1,4))
					PicB = viz.add(PictureB)
					yield viztask.waitTime()

I know there must be a lot of things wrong in this code (apart from the if statement - maybe the rationale behind the changing of the screen windows?), but it sort of worked until I had the if condition (7 and 3 out of 10). I've played around with it and sometimes I still get the sound to play, but at no point have I managed to change the lower screen, even without a complex condition attached to it.

I would be happy to receive some pointers in the right direction! At the moment there are probably a lot of things to improve and it is impossible for me to isolate one aspect to test it around.

Thank you very much in advance for your help!
Reply With Quote