Brown2020 / scripts /runChoice.m
jalauer's picture
Add files using upload-large-folder tool
227148b verified
function trial = runChoice(disp_struct, task_struct, trial, TRAINTEST, ioObject, LTP1address)
% Fixation
JIT=Shuffle(.3:.001:.5);
fixation_text = '+';
DrawFormattedText(disp_struct.wPtr,fixation_text,'center','center');
Screen(disp_struct.wPtr, 'Flip');
WaitSecs(JIT(1));
% get the center for the screen
center_x = round(disp_struct.wPtr_rect(3)/2);
center_y = round(disp_struct.wPtr_rect(4)/2);
% define the text font
Screen('TextSize', disp_struct.wPtr, 40);
Screen('TextFont', disp_struct.wPtr, 'Times');
Screen('TextStyle', disp_struct.wPtr, 0);
Screen('TextColor', disp_struct.wPtr, [255 255 255]);
Screen('FillRect', disp_struct.wPtr,[0 0 0]);
% stimuli bounds
sWidth = 300;
sHeight = 300;
sTop = center_y - sHeight/2;
sL_left = center_x - 80 - sWidth;
sR_left = center_x + 80;
sL_rect = [sL_left, sTop, sL_left + sWidth, sTop + sHeight];
sR_rect = [sR_left, sTop, sR_left + sWidth, sTop + sHeight];
% define the left and right stimuli
if trial(task_struct.cIsS1Left)
respL = trial(task_struct.cS1);
respR = trial(task_struct.cS2);
s1Rect = sL_rect;
s2Rect = sR_rect;
else
respL = trial(task_struct.cS2);
respR = trial(task_struct.cS1);
s1Rect = sR_rect;
s2Rect = sL_rect;
end
% show the stimuli
Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS1)), [], s1Rect);
Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS2)), [], s2Rect);
io64(ioObject,LTP1address,3); WaitSecs(.05); io64(ioObject,LTP1address,0);
% see if we need to frame the nc stim
if trial(task_struct.cTrialCond) == task_struct.NC
if trial(task_struct.cRespAct) == trial(task_struct.cS1)
ncFrameRect = s1Rect;
else
ncFrameRect = s2Rect;
end
Screen('FrameRect', disp_struct.wPtr, [0 0 255], ncFrameRect, 5);
end % frame the fc selected stim
% limit input
RestrictKeysForKbCheck([disp_struct.RESP_L, disp_struct.RESP_R]);
KbReleaseWait();
% flip to show the stims
[VBLTimestamp StimulusOnsetTime FlipTimestamp Missed Beampos] = Screen(disp_struct.wPtr, 'Flip', 0, 1);
% % % wait for response
% % [secs, keyCode, deltaSecs] = KbWait([], 2, GetSecs()+task_struct.maxRT);
wait_stamp=GetSecs;
while 1
[a ab] = JoyMEX(0);
if find(ab) ~= 0
if ab(1,disp_struct.RESP_L) == 1
stim_resp = disp_struct.RESP_L;
io64(ioObject,LTP1address,4); WaitSecs(.05); io64(ioObject,LTP1address,0);
break;
elseif ab(1,disp_struct.RESP_R) == 1
stim_resp = disp_struct.RESP_R;
io64(ioObject,LTP1address,5); WaitSecs(.05); io64(ioObject,LTP1address,0);
break;
end
elseif(GetSecs-wait_stamp) > task_struct.maxRT,
stim_resp=999;
break;
end
end
% compute the RT
RT = GetSecs - StimulusOnsetTime;
if stim_resp == disp_struct.RESP_L
% left-most action
choice = respL;
% hide the non-selected stim
Screen('FillRect', disp_struct.wPtr, [0 0 0], sR_rect);
% hide selection
Screen(disp_struct.wPtr, 'Flip');
WaitSecs(0.75);
elseif stim_resp == disp_struct.RESP_R
% right-most action
choice = respR;
% hide the non-selected stim
Screen('FillRect', disp_struct.wPtr, [0 0 0], sL_rect);
% hide selection
Screen(disp_struct.wPtr, 'Flip');
WaitSecs(0.75);
else
% they didn't respond in time
choice = disp_struct.RESP_SLOW;
end
% make sure they matched if this was a no-choice trial
if trial(task_struct.cTrialCond) == task_struct.NC && choice == trial(task_struct.cRespAct)
trial(task_struct.cMatch) = true;
else
trial(task_struct.cMatch) = false;
end
% do not update the response if they didn't match
if trial(task_struct.cTrialCond) == task_struct.FC || trial(task_struct.cMatch)
% store response
trial(task_struct.cRespAct) = choice;
trial(task_struct.cRT) = RT;
end
% --------------------------------------- FB
if TRAINTEST==1
% define the text font
Screen('TextSize', disp_struct.wPtr, 60);
Screen('TextFont', disp_struct.wPtr, 'Times');
Screen('TextStyle', disp_struct.wPtr, 0);
Screen('TextColor', disp_struct.wPtr, [255 255 255]);
Screen('FillRect', disp_struct.wPtr,[0 0 0]);
% get feedback for the selected stimulus
if trial(task_struct.cTrialCond) == task_struct.NC && ~trial(task_struct.cMatch)
fbText = 'You must match the framed symbol';
respRew = NaN;
SIMPLEFB=1;
FBTRIGGER=6;
elseif trial(task_struct.cRespAct) == trial(task_struct.cS1)
% they picked stim 1
respRew = trial(task_struct.cS1Rew);
fbText = num2str(respRew);
SIMPLEFB=0;
FBTRIGGER=10+respRew;
elseif trial(task_struct.cRespAct) == trial(task_struct.cS2)
% they picked stim 2
respRew = trial(task_struct.cS2Rew);
fbText = num2str(respRew);
SIMPLEFB=0;
FBTRIGGER=10+respRew;
else
% they responded too slow
fbText = ['Too Slow!\nYou must respond in under ' num2str(task_struct.maxRT) ' seconds'];
respRew = NaN;
SIMPLEFB=1;
FBTRIGGER=7;
end
if respRew==0
Screen('TextSize', disp_struct.wPtr, 100);
Screen('TextColor', disp_struct.wPtr, [255 0 0]);
elseif respRew==1
Screen('TextSize', disp_struct.wPtr, 100);
Screen('TextColor', disp_struct.wPtr, [0 255 0]);
end
% show the feedback
if SIMPLEFB==1
io64(ioObject,LTP1address,FBTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
DrawFormattedText(disp_struct.wPtr, fbText, 'center', 'center');
Screen(disp_struct.wPtr, 'Flip');
WaitSecs(0.75);
Screen(disp_struct.wPtr, 'Flip');
else
% FIRST show the selected stim
Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS1)), [], s1Rect);
Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS2)), [], s2Rect);
% Blank out the alternative
if trial(task_struct.cRespAct) == respL
Screen('FillRect', disp_struct.wPtr, [0 0 0], sR_rect);
elseif trial(task_struct.cRespAct) == respR
Screen('FillRect', disp_struct.wPtr, [0 0 0], sL_rect);
end
% If forced, show the box
if trial(task_struct.cTrialCond) == task_struct.NC
if trial(task_struct.cRespAct) == trial(task_struct.cS1)
ncFrameRect = s1Rect;
else
ncFrameRect = s2Rect;
end
Screen('FrameRect', disp_struct.wPtr, [0 0 255], ncFrameRect, 5);
end
% Next show the FB
io64(ioObject,LTP1address,FBTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
DrawFormattedText(disp_struct.wPtr, fbText, 'center', 'center');
Screen(disp_struct.wPtr, 'Flip');
WaitSecs(1.25);
Screen(disp_struct.wPtr, 'Flip');
end
clear FBTRIGGER;
Screen('TextSize', disp_struct.wPtr, 60);
Screen('TextColor', disp_struct.wPtr, [255 255 255]);
% store the feedback
trial(task_struct.cRespRew) = respRew;
end
end % function