Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Globals relating to experiment control
- int blockRun = 0;
- bool reverseBlocks = false; # Change this to true to reverse block selection (set 2 comes first)
- ## Globals relating to output
- string feedback, subject_info, outfile_name, timelock, blocktype="1Practice";
- string outfile_suffix = ".txt";
- string trigger_accuracy = "";
- string eeg_trigger = "";
- string trial_description = "prac";
- output_file outfile = new output_file;
- int blink_break = 7; #80 trials per block + 4 catch trials = 42 trials
- int between_block_break = 84;
- int trial_num = 1, block_num = 1, correct_trials = 0, trials_so_far = 0;
- int calc_port_code;
- int min_ISI = 400, max_ISI = 900, long_ISI_duration = 1000, actual_ISI, calc_ISI_duration; # ISI timing variables
- array <string> parts[5]; # For storing the various description details
- ## Globals relating to trial display
- # Picture counters
- int happy_pics = 80;
- int sad_pics = 80;
- int gloloc_pics = 4;
- int total_pics = happy_pics+sad_pics;
- int failures = -1;
- # Picture arrays
- array <int> trial_order[2];
- array <int> block1[happy_pics/2+sad_pics/2];
- array <int> block2[happy_pics/2+sad_pics/2];
- array <int> global_local_array[total_pics];
- #------------ subroutine to write out a line of breaks ------------
- sub
- update_output_file_break
- begin
- outfile.print( subject_info + "\t");
- outfile.print( string(trial_num) + "\t"); # current trial number
- outfile.print( string(block_num) + "\t"); # current block number
- loop
- int i = 1;
- until
- i > 17 # write break in 17 additional columns
- begin
- outfile.print( "break" + "\t"); # print break instead just to include the line in output
- i = i + 1;
- end;
- outfile.print( "break" + "\n"); # and the final column
- end;
- /*sub
- update_output_file_oddemotion
- begin
- outfile.print( subject_info + "\t");
- outfile.print( string(trial_num) + "\t"); # current trial number
- outfile.print( string(block_num) + "\t"); # current block number
- outfile.print ( string( stimulus_manager.last_stimulus_data().button()) + "\t" );
- outfile.print( "\n"); # and the final column
- end;
- */
- #------------- subroutine to write the column headings for the output file
- sub
- header_output_file
- begin
- outfile.print("subject"
- + "\t" + "trial"
- + "\t" + "emotion"
- + "\t" + "gender"
- + "\t" + "gaze"
- + "\t" + "pic#"
- + "\t" + "part_trigger" #AML1, AML1Bg
- + "\t" + "blocktype"
- + "\t" + "gloloc"
- + "\t" + "glopic"
- + "\t" + "event_code"
- + "\t" + "face_filename"
- + "\t" + "gloloc_filename"
- /*+ "\t" + "RT-EMO"
- + "\t" + "resp_button-EMO"
- + "\t" + "accuracy-EMO" */
- + "\t" + "ISI"
- + "\t" + "resp_port_code"
- + "\t" + "time_lock"
- + "\t" + "stim_port_code"
- + "\t" + "RT-GL"
- + "\t" + "resp_button-GL"
- + "\t" + "accuracy-GL"
- + "\t" + "trigger"
- + "\n");
- end;
- #------------ subroutines to write out the trial ------------
- sub
- output_one_line ( int type, string filename)
- begin
- trial_description = stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).event_code() + ", " + stimulus_manager.last_stimulus_data().event_code();
- outfile.print(trial_description+"\n");
- trial_description.split( ",", parts );
- string current_resp = "miss";
- parts[5] = parts[5] + parts[6].substring(1,1); # add blocktype (h#, n# or a#) to the part trigger
- array <string> fileparts[2];
- filename.split(" ", fileparts);
- outfile.print ( subject_info + "\t" );
- outfile.print ( string(trial_num) + "\t" ); # current trial number
- loop int p = 1 until p > parts.count() # print up until non-shared fields
- begin
- outfile.print( parts[p] + "\t");
- p = p + 1;
- end;
- /*if(type == 1) then # For the face stimulus
- outfile.print( "" + "\t"); # gloloc
- outfile.print( "" + "\t"); # gloloc image number
- outfile.print ( trial_description + "\t" );
- outfile.print ( fileparts[1] + "\t" );
- outfile.print ( "" + "\t");
- outfile.print ( "" + "\t");
- outfile.print ( "" + "\t");
- outfile.print ( "" + "\t");
- outfile.print ( string(actual_ISI) + "\t" );
- outfile.print ( "" + "\t");
- timelock = "stimlock";
- else # For the gloloc & response*/
- outfile.print ( trial_description + "\t" );
- outfile.print ( fileparts[1] + "\t");
- outfile.print ( fileparts[2] + "\t" );
- /*outfile.print ( string( stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).reaction_time()) + "\t" ); # rt
- outfile.print ( string( stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).button()) + "\t" ); # response button
- trigger_accuracy = "e";
- if stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_hit then
- current_resp = "hit";
- trigger_accuracy = "c";
- correctanswer = true;
- elseif stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_miss then current_resp = "miss";
- elseif stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_incorrect then current_resp = "error";
- else current_resp = "other";
- end;
- outfile.print ( current_resp + "\t" ); # accuracy as hit miss error other */
- outfile.print ( string(actual_ISI) + "\t" );
- string current_button_code;
- if stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_miss
- then current_button_code = "none";
- else
- current_button_code = string( stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() );
- end;
- outfile.print ( current_button_code + "\t" ); # button code is erp response port code
- if(type==2) then
- timelock = "stimlock";
- else
- timelock = "resplock";
- end;
- # end;
- outfile.print(timelock + "\t"); # timelock
- outfile.print( string(calc_port_code) + "\t" ); # port out stimulus port code
- eeg_trigger = "2";#eeg_trigger = parts[5];
- if(type != 1) then
- eeg_trigger = eeg_trigger + parts[parts.count()];
- end;
- # if(type == 4) then
- outfile.print ( string( stimulus_manager.last_stimulus_data().reaction_time()) + "\t" ); # rt
- outfile.print ( string( stimulus_manager.last_stimulus_data().button()) + "\t" ); # response button
- trigger_accuracy = "e";
- current_resp = "miss";
- if stimulus_manager.last_stimulus_data().type() == stimulus_hit then
- current_resp = "hit";
- correct_trials = correct_trials + 1;
- trigger_accuracy = "c";
- elseif stimulus_manager.last_stimulus_data().type() == stimulus_miss then current_resp = "miss";
- elseif stimulus_manager.last_stimulus_data().type() == stimulus_incorrect then current_resp = "error";
- else current_resp = "other";
- end;
- outfile.print ( current_resp + "\t" ); # accuracy as hit miss error other
- /* else
- outfile.print( "\t");
- outfile.print( "\t");
- outfile.print( "\t");
- end;*/
- outfile.print(timelock.substring(1,1)+eeg_trigger+trigger_accuracy + "\n");
- outfile.print(stimulus_manager.stimulus_count());
- end;
- sub
- showBreaks
- begin
- # note the following works only if between_block_break is divisible by blink_break
- if mod(trial_num, blink_break) == 0 && trial_num != total_pics # provide blink breaks
- then
- feedback = "You got " + string(correct_trials) + " out of " + string(trials_so_far) + " correct.";
- text_accuracy.set_caption (feedback);
- text_accuracy.redraw();
- if mod(trial_num, between_block_break) == 0 && trial_num != total_pics
- # provide longer breaks between blocks
- then
- #oddemotion_trial.present();
- #update_output_file_oddemotion();
- block_break_trial.present();
- update_output_file_break(); # write line in output for blink break so match trigger file
- # this port out time timelocked to the response
- # picture onset does not port out, is this because there is no port_code for the trial?
- else
- break_trial.present();
- update_output_file_break(); # write line in output for blink break so match trigger file
- # this port out time timelocked to the response
- end; # if between_block_break
- correct_trials = 0; # reset for next set of trials
- trials_so_far = 0;
- ISI_event.set_duration (long_ISI_duration );
- ISI_trial.present();
- end; # if blink break
- trial_num = trial_num + 1; # update after every stimulus presentation
- eeg_trigger = ""; # reset the eeg_trigger
- trial_description = "";
- end; # of subroutine
- sub
- generate_global_local_array
- begin
- loop int j=1 until j > global_local_array.count()
- begin
- # Assign global_local associations for all pictures
- # Two straight pictures should be opposites
- global_local_array[j] = 1; # Straight Pic 1 -- Random!
- global_local_array[j+1] = 2; # Straight Pic 2 --
- j=j+2;
- end;
- end;
- sub
- validate_array( array< int, 1> &validateArray, bool checkGL)
- begin
- int last_seen_gl = -1, last_seen_img = -1, last_last_seen_img = -1;
- loop int j=1 until j > validateArray.count()
- begin
- if((global_local_array[validateArray[j]] == last_seen_gl && checkGL==true) ||
- ((validateArray[j]/84) == last_seen_img && last_seen_img == last_last_seen_img) ) then # Something is wrong.
- #outfile.print("\nSomething is wrong! Image #: "+string(validateArray[j]));
- #outfile.print(" emotion match: "+string(validateArray[j]/132)+"=="+string(last_seen_img)+"=="+string(last_last_seen_img)+"\n");
- #outfile.print(" gl match: "+string(global_local_array[validateArray[j]])+"=="+string(last_seen_gl)+"\n");
- loop int k=j+1 until k > validateArray.count() # search for a valid picture
- begin
- if((global_local_array[validateArray[k]] != last_seen_gl || checkGL==false) && !(((validateArray[k]/84) == last_seen_img) && (last_seen_img==last_last_seen_img))) then
- #outfile.print("\n Swapping with! Image #: "+string(validateArray[k]));
- #outfile.print("emotion change: "+string(validateArray[j]/132)+" to "+string(validateArray[k]/132));
- #outfile.print(" gl change: "+string(global_local_array[validateArray[j]])+" to "+string(global_local_array[validateArray[k]])+"\n");
- int temp = validateArray[j];
- validateArray[j] = validateArray[k];
- validateArray[k] = temp;
- break;
- else
- #outfile.print("F: I#"+string(validateArray[k])+" E#"+string(validateArray[k]/132)+" G#"+string(global_local_array[validateArray[k]])+"\n");
- end;
- k = k + 1;
- if(k > validateArray.count()) then
- #outfile.print("\nFailed to swap in! Image #: "+string(validateArray[j])+"\n");
- failures = failures+1;
- end;
- end;
- end;
- last_seen_gl = global_local_array[validateArray[j]]; # Get the G/L indicator for this picture
- last_last_seen_img = last_seen_img;
- last_seen_img = (validateArray[j]/84);
- j = j + 1;
- end;
- end;
- sub
- generate_block_arrays( array< int, 1 >& block_array1, array< int, 1>& block_array2, int num_pics)
- begin
- int k = 1; #k = the picture's place within each of the arrays while j= the picture number overall
- loop int j=1 until j > (num_pics)
- begin
- block_array1[k] = j; # Straight
- block_array2[k+1] = j+1; # Straight2
- block_array2[k] = j+2; # Straight1
- block_array1[k+1] = j+3; # Straight2
- if(j+3 >= (num_pics)) then
- break;
- end;
- block_array1[k] = j; # Straight
- block_array2[k+1] = j+1; # Straight2
- block_array2[k] = j+2; # Straight1
- block_array1[k+1] = j+3; # Straight2
- j=j+4; # Onto the next set of 4 people
- k=k+2; # Onto the next set of 4 people (divided into two arrays)
- end;
- block_array1.shuffle();
- block_array2.shuffle();
- validate_array(block_array1, true);
- outfile.print("\n************************************************************\n");
- validate_array(block_array2, true);
- /*loop int mir=1 until mir>block_array1.count()
- begin
- outfile.print(string(block_array1[mir])+" ");
- mir = mir + 1;
- end;
- outfile.print("\n");
- loop int mir=1 until mir>block_array2.count()
- begin
- outfile.print(string(block_array2[mir])+" ");
- mir = mir + 1;
- end;
- loop int mir=1 until mir>block_array1.count()
- begin
- string x = face_pics[block_array1[mir]].filename();
- outfile.print(x + "\n");
- mir = mir + 1;
- end;
- outfile.print("\n");
- loop int mir=1 until mir>block_array2.count()
- begin
- string x = face_pics[block_array2[mir]].filename();
- outfile.print(x + "\n");
- mir = mir + 1;
- end;
- outfile.print("\n");*/
- end;
- sub
- trials_display( array< int, 1 >& displayArray, int portCode, int emotion)
- begin
- array <string> fileparts[4];
- int catchCounter = 0;
- loop int j=1 until j > displayArray.count()
- begin
- int pic_index;
- calc_ISI_duration = random(min_ISI,max_ISI);
- ISI_event.set_duration (calc_ISI_duration);
- actual_ISI = calc_ISI_duration + 1500 - 250; # these should be set as variables at some point
- # Replace placeholder face with face
- bitmap actual_face;
- if((j == 27 && catchCounter == 0) || (j == 54 && catchCounter == 1))
- then
- # face pics= total pics in the experiment represented in an array
- actual_face = catch_pics[catchCounter+1];
- else
- actual_face = face_pics[(displayArray[j])];
- end;
- face_picture.set_part(1,actual_face); # replace the PLACEHOLDER with the actual picture that was selected
- show_face.set_stimulus(face_picture); # the picture is the stimulus!
- show_face.set_event_code(actual_face.description() + ","+blocktype);
- calc_port_code = 102;
- show_face.set_port_code(calc_port_code);
- # Replace placeholder with global/local
- int gloloc_index;
- int gloaccess = displayArray[j];
- if((j == 27 && catchCounter == 0) || (j == 54 && catchCounter == 1))
- then
- gloaccess = gloaccess - 1;
- end;
- if(global_local_array[gloaccess] == 1) then #this checks to see which global-local stim should be shown with this face
- gloloc_index = random(1,gloloc_pics/2);
- else
- gloloc_index = random((gloloc_pics/2+1),gloloc_pics);
- end;
- /*
- if(displayArray[j] <= 132) then
- show_face.set_target_button(1);
- else
- show_face.set_target_button(2);
- end;
- */
- if(gloloc_index == 1 || gloloc_index == 3) then ## 2
- show_gloloc.set_target_button(2);
- else ## 5
- show_gloloc.set_target_button(1);
- end;
- bitmap actual_gloloc = global_local_pics[gloloc_index];
- gloloc_picture.set_part(1,actual_gloloc);
- show_gloloc.set_stimulus(gloloc_picture);
- show_gloloc.set_event_code(actual_gloloc.description());
- calc_port_code = 103;
- show_gloloc.set_port_code(calc_port_code);
- show_trial.present();
- string x = actual_face.filename(), flname;
- x.split("\\", fileparts); # Split the filename by directory
- flname = fileparts[fileparts.count()]; # Take the last item (filename.jpg)
- x = actual_gloloc.filename();
- x.split("\\", fileparts);
- flname = flname + " " + fileparts[fileparts.count()]; # Take both filenames together
- output_one_line(1,flname); # Write relevant data
- #show_gloloc_trial.present(); # Show the global/loc portion of the trial
- #output_one_line(2, flname); # Write relevant data
- #output_one_line(3, flname);
- #utput_one_line(4, flname);
- ISI_trial.present();
- trials_so_far = trials_so_far + 1;
- showBreaks();
- if((j == 27 && catchCounter == 0) || (j == 54 && catchCounter == 1)) then
- catchCounter = catchCounter + 1;
- else
- j=j+1;
- end;
- end;
- end;
- sub
- output_prac ( string filename)
- begin
- trial_description = stimulus_manager.last_stimulus_data().event_code();
- outfile.print ( subject_info + "\t" );
- outfile.print ( string(trial_num) + "\t" ); # current trial number
- outfile.print ( trial_description + "\t" );
- outfile.print ( filename + "\t");
- outfile.print ( string( stimulus_manager.last_stimulus_data().reaction_time()) + "\t" ); # rt
- string current_resp = "miss";
- if stimulus_manager.last_stimulus_data().type() == stimulus_hit then
- current_resp = "hit";
- elseif stimulus_manager.last_stimulus_data().type() == stimulus_miss then current_resp = "miss";
- elseif stimulus_manager.last_stimulus_data().type() == stimulus_incorrect then current_resp = "error";
- else current_resp = "other";
- end;
- outfile.print ( current_resp + "\t" ); # accuracy as hit miss error other
- outfile.print("\n");
- end;
- sub prac
- begin
- int gloloc_index= 0;
- string x, flname;
- array <string> fileparts[4];
- loop int j=1 until j > 21
- begin
- if (j%2==0) then #this checks to see which global-local stim should be shown with this face
- gloloc_index = random(1,gloloc_pics/2);
- else
- gloloc_index = random((gloloc_pics/2+1),gloloc_pics);
- end;
- if(gloloc_index == 1 || gloloc_index == 3) then ## 2
- show_gloloc.set_target_button(1);
- else ## 5
- show_gloloc.set_target_button(2);
- end;
- bitmap actual_gloloc = global_local_pics[gloloc_index];
- gloloc_picture.set_part(1,actual_gloloc);
- show_gloloc.set_stimulus(gloloc_picture);
- show_gloloc.set_event_code(actual_gloloc.description());
- calc_port_code = 103;
- show_gloloc.set_port_code(calc_port_code);
- #show_gloloc_trial.present(); # Show the global/loc portion of the trial
- x = actual_gloloc.filename();
- x.split("\\", fileparts);
- flname = flname + " " + fileparts[fileparts.count()]; # Take both filenames together
- output_prac( flname); # Write relevant data
- ISI_trial.present();
- j= j+1;
- end;
- begin
- prac_block_break_trial.present();
- update_output_file_break();
- end;
- end;
- # start of experiment
- subject_info = logfile.subject(); # get subject info from Pres. setting in "Logfiles" tab
- #blockRun = int(subject_info)%6;
- logfile.set_filename( subject_info + ".log" ); # set Pres logfile to same name as subject info sets the log name
- outfile_name = subject_info + outfile_suffix; # set up output file sets the txt file name
- outfile.open_append( outfile_name );
- header_output_file(); # write the output column headers
- begin_trial.present(); # welcome and instructions- refers back to scenario file where the instructions are described
- ISI_event.set_duration (long_ISI_duration ); #change the duration of ISI event to be a longer break before start of block and start of experiment
- ISI_trial.present();
- block_num = 1;
- generate_global_local_array();
- loop until failures==0 begin
- failures = 0;
- generate_block_arrays(block1,block2, total_pics);
- if(failures > 0) then
- outfile.print(string(failures) + " failures detected. Reassigning arrays.\n");
- end;
- end;
- /*loop int i=1 until i > happy_pics/2
- begin
- string x = string(happy_array1[i]);
- bitmap actual_face = face_pics[(happy_array1[i])];
- string x = actual_face.filename();
- outfile.print(x + "\n");
- i = i+1;
- end;
- /* creating alternate block orders is not
- necessary for esp02 since all blocks contain mixed emotions
- if blockRun == 0 then
- trial_order = {1,2,3,4,5,6};
- elseif blockRun == 1 then
- trial_order = {2,3,1,5,6,4};
- elseif blockRun == 2 then
- trial_order = {2,1,3,5,4,6}
- elseif blockRun == 3 then
- trial_order = {3,1,2,6,4,5};
- elseif blockRun == 4 then
- trial_order = {3,2,1,6,5,4};
- elseif blockRun == 5 then
- trial_order = {1,3,2,4,6,5};
- end;
- */
- trial_order = {1,2};
- trial_order.shuffle();
- #prac();
- loop int j=1 until j > trial_order.count()
- begin
- if(trial_order[j] == 1) then
- blocktype = "1Block";
- trials_display(block1,100, 2);
- elseif(trial_order[j] == 2) then
- blocktype = "2Block";
- trials_display(block2,100, 0);
- end;
- block_num = block_num + 1;
- j = j+1;
- end;
- thanks_trial.present(); # goodbye
Add Comment
Please, Sign In to add comment