![]() |
|
|
|
#1
|
|||
|
|||
|
The following is a short example script that loops through 3 trials in a task function. Each trial loops for the number of images in the images list. For each image loop the program waits for either the 'y' or 'n' key to be pressed:
Code:
import viz
import viztask
import random
viz.go()
#Store images in list
images = []
def experiment():
#Repeat trial 3 times
for i in range(3):
#Use random.shuffle to put images in random order
random.shuffle(images)
#Cycle through images
for image in images:
#display image
#wait for 'y' or 'n' key to be pressed
data = yield viztask.waitKeyDown(('y','n'))
print data.key
#remove image and let user know if response is correct
viztask.schedule( experiment() )
|
|
#2
|
|||
|
|||
|
Hi,
That's absolutely brilliant, thank you so much for your help it's really helped me to put the experiment together! I have one more question however. Within my 15 insects there are 5 'models' and 10 mimics'. Models sting, whereas mimics don't and therefore I need to display different answers for each - which I am having trouble with. Here's the code that I've put. In the images the models are labelled 1 to 5 and the mimics are labelled 6 to fifteen. I've also tried seperating them into 2 seperate lists 'stinging' and 'non-stinging' however, the problem with this is I then can't get them to shuffle randomly between the two. Any ideas? viz.go() #Store images in list images = [one,two,three,four,five,six,seven,eight,nine,ten,e leven,twelve,thirteen,fourteen,fifteen] def testPhase(): #Repeat trial 3 times for i in range (3): #Make background visible background.visible(viz.ON) #Add focus point focus.visible(viz.ON) #Use random.shuffle to put images in a random order random.shuffle(images) #Cycle through images for image in images: #Wait 3 seconds for participant to look at focus point yield viztask.waitTime(3) #Remove focus point focus.visible(viz.OFF) #display image image.visible(viz.ON) #Mark the time the programme started start_time = viz.tick() question_data = open('experiment_data.txt','a') #Wait for 'y' or 'n' key to be pressed d = yield viztask.waitKeyDown(['y','n']) elapsed_time = viz.tick() - start_time #remove image and let user know if response is correct #write data to file if image == one or two or three or four or five: if d.key == 'y': image.visible(viz.OFF) data = 'Participant' + ' Thinks the insect would sting.\t' correct.visible(viz.ON) correctPoints.visible(viz.ON) info.visible(viz.ON) if d.key == 'n': image.visible(viz.OFF) data = 'Participant' + ' Does not think the insect would sting.\t' wrong.visible(viz.ON) wrongPoints.visible(viz.ON) info.visible(viz.ON) if image == six or seven or eight or nine or ten or eleven or twelve or thirteen or fourteen or fifteen: if data == 'n': image.visible(viz.OFF) data = 'Participant' + ' Does not think the insect would sting.\t' correct.visible(viz.ON) correctPoints.visible(viz.ON) info.visible(viz.ON) if data == 'y': image.visible(viz.OFF) data = 'Participant' + ' Thinks the insect would sting.\t' wrong.visible(viz.ON) wrongPoints.visible(viz.ON) info.visible(viz.ON) #add elapsed time to data data = str(image) + data + ' Elapsed time was: ' + str(round(elapsed_time,2)) + ' seconds\n' #Write the data to our file. question_data.write(data) #Press space bar to start the game yield viztask.waitKeyDown(' ') #Remove score correct.visible(viz.OFF) correctPoints.visible(viz.OFF) wrong.visible(viz.OFF) wrongPoints.visible(viz.OFF) info.visible(viz.OFF) focus.visible(viz.ON) viz.quit() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| compiled exe won't save trials to AVI | krimble | Vizard | 1 | 01-29-2014 12:32 PM |
| running experimental trials | fivel_lab | Vizard | 3 | 03-18-2011 03:58 PM |