#1
|
|||
|
|||
How to set up trials?
Hi,
I'm wondering if anyone can help me. I've designed an experiment but unfortunately since I'm not really familiar with vizard or coding I've coded for it very long-hand. I've been told that before I can get the experiment up and running I need to re-organise my code to get it running in a loop of trials, however, I have absolutely no idea how to do this!!!! I've copied the code below. If anyone could give me any pointers that would be fantastic p.s. I've not copied the full code as it goes on forever but essentially there are 10 repeats of the same thing in the test phase! import viz import viztask import vizact import vizinfo import vizmat import vizshape viz.setMultiSample viz.fov(60) viz.go() viz.window.setSize(-1); #set to full screen #Add score labels for trial 1 success = viz.addText('You ate the insect!', viz.SCREEN) success_points = viz.addText('+5 points', viz.SCREEN) fail = viz.addText('You got stung!', viz.SCREEN) fail_points = viz.addText('-5 points', viz.SCREEN) info_one = vizinfo.add('Press the space bar to try again') info_one.translate(0.70,0.3) #Make score labels invisible success.visible(viz.OFF) success_points.visible(viz.OFF) fail.visible(viz.OFF) fail_points.visible(viz.OFF) info_one.visible(viz.OFF) #Add score labels for trial 2 successTwo = viz.addText('You ate the insect!', viz.SCREEN) success_pointsTwo = viz.addText('+5 points', viz.SCREEN) failTwo = viz.addText('You got stung!', viz.SCREEN) fail_pointsTwo = viz.addText('-5 points', viz.SCREEN) info_two = vizinfo.add('Press the space bar to try again') info_two.translate(0.70,0.3) #Make score labels invisible successTwo.visible(viz.OFF) success_pointsTwo.visible(viz.OFF) failTwo.visible(viz.OFF) fail_pointsTwo.visible(viz.OFF) info_two.visible(viz.OFF) def participantInfo(): #add the vizinfo box infoBox = vizinfo.add('') infoBox.scale(2,2) infoBox.translate(0.85,0.8) infoBox.title('Participant Info') #Add the GUI elements to the box participantNumber = infoBox.add(viz.TEXTBOX,'Participant Number') experimentNumber = infoBox.add(viz.TEXTBOX,'Experiment Number') runButton = infoBox.add(viz.BUTTON,'Run') #Wait for run button to be pressed before moving on yield viztask.waitButtonUp(runButton) #get data from text boxes and then remove the info box participant = participantNumber.get() number = experimentNumber.get() infoBox.remove() #open a text file experiment_data = open('experiment_data.txt','a') #write participant data to file data = "Experiment Number: %s\tParticipant: %s\n\n" % (number,participant) experiment_data.write(data) def learnPhase(): #Add grass background quadTwo = viz.addTexQuad(pos=[0, 1.8, 1.7], size=2.75) textureTwo = viz.addTexture('Grass.png') quadTwo.texture(textureTwo) #Add insect example quadOne = viz.addTexQuad(pos=[0,1.80,1.6]) texture = viz.addTexture('model_one.png') quadOne.texture(texture) #Add instructions of what to do instruction = viz.addText('Eat insects to score points!',viz.SCREEN) instruction.alignment(viz.ALIGN_CENTER_TOP) instruction.setPosition(0.5,0.9) info = vizinfo.add('Press the space bar to begin') info.translate(0.65,0.2) #Start test phase with space bar yield viztask.waitKeyDown(' ') info.remove() quadOne.remove() instruction.remove() def testPhaseOne(): #Wait 3 seconds before loading the next image yield viztask.waitTime(3) #Add a critical question critical_question = viz.addText('Would you eat this insect?',viz.SCREEN) yes = viz.addText('Eat!',viz.SCREEN) no = viz.addText('Do not eat!',viz.SCREEN) critical_question.alignment(viz.ALIGN_CENTER_TOP) critical_question.setPosition(0.5,0.9) yes.alignment(viz.ALIGN_LEFT_TOP) yes.setPosition(.15,.30) no.alignment(viz.ALIGN_LEFT_TOP) no.setPosition(.60,.30) yes_button = viz.addButton() yes_button.setPosition(.13,.26) no_button = viz.addButton() no_button.setPosition(.57,.26) #Add model 1 quadOne = viz.addTexQuad(pos=[0.1,1.80,1.5]) texture = viz.addTexture('model.png') quadOne.texture(texture) #Mark the time the programme started start_time = viz.tick() question_data = open('experiment_data.txt','a') def onbutton(obj,state): #Use our starting time variable to find out how much #time has elapsed. elapsed_time = viz.tick() - start_time #Create string lines to put in the data file, depending on which #button was pushed. if obj == yes_button: data = 'Participant' + ' ate the insect.\t' success.setPosition(0.5,0.7) success_points.alignment(viz.ALIGN_CENTER_CENTER) fail_points.alignment(viz.ALIGN_CENTER_CENTER) fail_points.setPosition(0.5,0.45) fail.visible(viz.ON) fail_points.visible(viz.ON) info_one.visible(viz.ON) if obj == no_button: data = 'Participant' + ' did not eat the insect.\t' fail.alignment(viz.ALIGN_CENTER_TOP) fail.setPosition(0.5,0.7) success_points.alignment(viz.ALIGN_CENTER_CENTER) success_points.setPosition(0.5,0.45) fail.visible(viz.ON) success_points.visible(viz.ON) info_one.visible(viz.ON) #add elapsed time to data data = data + 'Elapsed time was: ' + str(round(elapsed_time,2)) + ' seconds\n' #Write the data to our file. question_data.write(data) #Flush the internal buffer. question_data.flush() #Remove the illustrations quadOne.remove() critical_question.remove() yes_button.remove() no_button.remove() yes.remove() no.remove() viz.callback(viz.BUTTON_EVENT,onbutton) def testPhaseTwo(): #Start test phase with space bar yield viztask.waitKeyDown(' ') #Remove score from previous trial success.remove() success_points.remove() fail.remove() fail_points.remove() info_one.remove() yield viztask.waitTime( 3 ) #Add a critical question critical_question = viz.addText('Would you eat this insect?',viz.SCREEN) yes = viz.addText('Eat!',viz.SCREEN) no = viz.addText('Do not eat!',viz.SCREEN) critical_question.alignment(viz.ALIGN_CENTER_TOP) critical_question.setPosition(0.5,0.9) yes.alignment(viz.ALIGN_LEFT_TOP) yes.setPosition(.15,.30) no.alignment(viz.ALIGN_LEFT_TOP) no.setPosition(.60,.30) yes_button = viz.addButton() yes_button.setPosition(.13,.26) no_button = viz.addButton() no_button.setPosition(.57,.26) #Add model 2 quadOne = viz.addTexQuad(pos=[0.10,1.80,1.5]) texture = viz.addTexture('model.png') quadOne.texture(texture) #Mark the time the programme started start_time = viz.tick() question_data = open('experiment_data.txt','a') def onbutton(obj,state): #Use our starting time variable to find out how much #time has elapsed. elapsed_time = viz.tick() - start_time #Create string lines to put in the data file, depending on which #button was pushed. if obj == yes_button: data = 'Participant' + ' ate the insect.\t' failTwo.alignment(viz.ALIGN_CENTER_TOP) failTwo.setPosition(0.5,0.7) fail_pointsTwo.alignment(viz.ALIGN_CENTER_CENTER) fail_pointsTwo.setPosition(0.5,0.45) failTwo.visible(viz.ON) fail_pointsTwo.visible(viz.ON) info_two.visible(viz.ON) if obj == no_button: data = 'Participant' + ' did not eat the insect.\t' successTwo.alignment(viz.ALIGN_CENTER_TOP) successTwo.setPosition(0.5,0.7) success_pointsTwo.alignment(viz.ALIGN_CENTER_CENTE R) success_pointsTwo.setPosition(0.5,0.45) successTwo.visible(viz.ON) success_pointsTwo.visible(viz.ON) info_two.visible(viz.ON) #add elapsed time to data data = data + 'Elapsed time was: ' + str(round(elapsed_time,2)) + ' seconds\n' #Write the data to our file. question_data.write(data) #Flush the internal buffer. question_data.flush() #Remove the illustrations quadOne.remove() critical_question.remove() yes_button.remove() no_button.remove() yes.remove() no.remove() viz.callback(viz.BUTTON_EVENT,onbutton) |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
compiled exe won't save trials to AVI | krimble | Vizard | 1 | 01-29-2014 11:32 AM |
running experimental trials | fivel_lab | Vizard | 3 | 03-18-2011 02:58 PM |