Hi there, I have created a program which displays four slides which are sequenced below.
1)Displays a fixation cross for 1 sec.
2)Displays a random integer for 5 sec.
If the key, 1 is pressed, the third display/slide is shown. The third display is a left arrow at the bottom with the random integer displayed on top of the arrow.
Now, if the key, 2 is pressed, the fourth display/slide is shown. The fourth display is a right arrow at the bottom with the random integer displayed on top of the arrow.
If, nothing is pressed or some other key is pressed within the duration(5 sec) of the second slide, the window will close.
Attached below is the program that i have come up with.
When i press 1 or 2, i cant seem to go to the next slide, it remains stuck at slide 2. I have tried Kbdemo.m and the Kb seems to work well with the demo programs, so, im pretty sure its this program that needs an alteration. Is there anyone who can help me with this. I would be most gracious.
%variables
whichscreen=0;
[window,rect]=Screen('OpenWindow',whichscreen,0);
[X,Y]=RectCenter(rect);
FixCross=[X-1,Y-40,X+1,Y+40;X-40,Y-1,X+40,Y+1];
x=num2str(randi(100));
xcenter=rect(3)/2;
ycenter=rect(4)/2;
KbName('UnifyKeyNames');
onekey=KbName('1');
twokey=KbName('2');
[keyIsDown,seconds,keyCode]=KbCheck;
%Slide 1
Screen('FillRect',window,[255 255 255],FixCross');
Screen(window,'Flip');
HideCursor;
WaitSecs(1);
%Slide 2
Screen('TextSize',window,150);
number=DrawFormattedText(window,x,'center','center',[255 255 255]);
Screen(window,'Flip');
WaitSecs(1);
if keyIsDown
if keycode(onekey)
%Slide 3
Screen('TextSize',window,150);
Screen('DrawText',window,x,xcenter-100,ycenter-200,[255 255 255]);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter+200,ycenter+200,5);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter-150,ycenter+250,5);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter-150,ycenter+150,5);
Screen(window,'Flip');
Screen('Close',window);
elseif keycode(twokey)
%Slide 4
Screen('TextSize',window,150);
Screen('DrawText',window,x,xcenter-100,ycenter-200,[255 255 255]);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter+200,ycenter+200,5);
Screen('DrawLine',window,[255 255 255],xcenter+150,ycenter+250,xcenter+200,ycenter+200,5);
Screen('DrawLine',window,[255 255 255],xcenter+150,ycenter+150,xcenter+200,ycenter+200,5);
Screen(window,'Flip');
Screen('Close',window);
else
Screen('Close',window);
end
end
1)Displays a fixation cross for 1 sec.
2)Displays a random integer for 5 sec.
If the key, 1 is pressed, the third display/slide is shown. The third display is a left arrow at the bottom with the random integer displayed on top of the arrow.
Now, if the key, 2 is pressed, the fourth display/slide is shown. The fourth display is a right arrow at the bottom with the random integer displayed on top of the arrow.
If, nothing is pressed or some other key is pressed within the duration(5 sec) of the second slide, the window will close.
Attached below is the program that i have come up with.
When i press 1 or 2, i cant seem to go to the next slide, it remains stuck at slide 2. I have tried Kbdemo.m and the Kb seems to work well with the demo programs, so, im pretty sure its this program that needs an alteration. Is there anyone who can help me with this. I would be most gracious.
%variables
whichscreen=0;
[window,rect]=Screen('OpenWindow',whichscreen,0);
[X,Y]=RectCenter(rect);
FixCross=[X-1,Y-40,X+1,Y+40;X-40,Y-1,X+40,Y+1];
x=num2str(randi(100));
xcenter=rect(3)/2;
ycenter=rect(4)/2;
KbName('UnifyKeyNames');
onekey=KbName('1');
twokey=KbName('2');
[keyIsDown,seconds,keyCode]=KbCheck;
%Slide 1
Screen('FillRect',window,[255 255 255],FixCross');
Screen(window,'Flip');
HideCursor;
WaitSecs(1);
%Slide 2
Screen('TextSize',window,150);
number=DrawFormattedText(window,x,'center','center',[255 255 255]);
Screen(window,'Flip');
WaitSecs(1);
if keyIsDown
if keycode(onekey)
%Slide 3
Screen('TextSize',window,150);
Screen('DrawText',window,x,xcenter-100,ycenter-200,[255 255 255]);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter+200,ycenter+200,5);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter-150,ycenter+250,5);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter-150,ycenter+150,5);
Screen(window,'Flip');
Screen('Close',window);
elseif keycode(twokey)
%Slide 4
Screen('TextSize',window,150);
Screen('DrawText',window,x,xcenter-100,ycenter-200,[255 255 255]);
Screen('DrawLine',window,[255 255 255],xcenter-200,ycenter+200,xcenter+200,ycenter+200,5);
Screen('DrawLine',window,[255 255 255],xcenter+150,ycenter+250,xcenter+200,ycenter+200,5);
Screen('DrawLine',window,[255 255 255],xcenter+150,ycenter+150,xcenter+200,ycenter+200,5);
Screen(window,'Flip');
Screen('Close',window);
else
Screen('Close',window);
end
end