[solved] collecting mouse and keyboard response while showing stimuli
Hi,
my name is Stefano and I am quite new to OpenSesame, although I really like it already. But I need some help implementing a dual task
Basically I want to show a stimulus with 4 rectangles and a line of text for 1500ms. The colors of the rectangles, and the text to be displayed are defined in a loop, and while the stimulus is on the screen I want to monitor for 1500 ms (the duration of the stimulus on the screen) both mouse clicks and keybord responses. In fact there are two simultaneous task to be performed: a) checking whethere 3 or more rectangles have the same fill color, and press space if that is the case, and b) whether there is a colon in the text line, and click on the mouse if that is the case. After a click or a keystroke, anyway, the stimulus must stay on the screen until 1500 ms have elapsed from the stimulus onset.
Given that there are two tasks to be performed simultaneously, in each trial there are two correct responses, one for task (a) and one for task (b), and I have set variables in the loop of condition to store (a) whether there are 3 or more rectangles of the same color or not (variable "correct_response", values: "space" if there are 3 or more rectangles with same fill color; "a" otherwise), (b) whether there is a colon in the text (variable "colon", values: 1 if there is a colon, 0 otherwise). For each task, at the end of a trial, I want to record in a variable whether there was a hit (the target condition was present, and the subject gave the correct response), a miss (the target was present, but the subject did not respond within 1500 ms) or an incorrect response (the target was NOT present, and the subject did respond as it was present).
I guess I need inline script to do that, but I'm not sure how to use them. Can anyone please help?
Thanks you in advance for any help you can provide me!
best,
Stefano
Comments
I forgot to say that in each trial, if there are not 3 or more rectangles of the same color, the subject should not press any key, and if there is not a colon in the text line, the subject should not click on the mouse button. In other words, each of the possible responses (keystroke and mouseclick) should be given if and only if the corresponding target is present.
Hi Stefano,
Right, you can certainly do this. It would require a bit of inline-code, but nothing overwhelming. But I was thinking (just a suggestion, perhaps you have good reasons for the paradigm as is) that the paradigm could be simplified a bit. What if you just define 4 keys, say like so:
If you decide to do it like this, you would always have one single response to each display, and you could use a single keyboard-response. The only thing that remains then, would be to pad the 1500ms using inline code (so that the display doesn't disappear when the participant presses a key) with an inline_script like this:
Does this make sense?
So that would be an option. If you don't think this is a good idea, could you please describe in more detail how you would like to handle responses? More specifically, is the participant allowed to press both the mouse and the key at any time, or is there a fixed order: first the key, than the mouse, or vice versa?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thanks for your prompt reply! I had thought initially about a solution like the one you suggested, but I discarded it for design reasons. In fact, I want the two tasks to be more separate, and independent among each other, and doing like you say would be like having a single task, with 4 possible responses to memorize, thus more complicated than two simple "press/click-if-target-is present" tasks. I have tried to code the inline script below, and I get a syntax error at the line in which I call self.time() and can't go forward. In any way I'm also starting to figure out why (syntax error aside) this algorithm can't work: I guess that is because once you call a keyboard() function, the program start waiting, and so you can't immediately after call a mouse() function!. So we could at least simplify to have the user only use keyboard to express responses, allowing him to do it twice in each trial (in case the target is present in both tasks), regardless of the order of responses.
Please let me know what you think and thank you a lot for your precious help (and for OpenSesame in general too!)
Stefano
Hi Stefano,
From what I can tell from the code, you're almost there. The only real problem appears to be the timeout. You now pass '1500' as a timeout to the keyboard and mouse classes. This means that get_key() and get_click() will block for 1500ms before returning a timeout.
What you actually want to do is set the timeout really low, to say 5ms. This way the keyboard and mouse can be polled intermittently, if you understand what I mean. Because you have a while loop that blocks for 1500ms (while elapsed_time <1500:) you will still have a 1500ms timeout, even though the timeout for each individual call of get_key() and get_click() is much lower.
Regarding the error: I don't see a syntax error in the line that says:
Is it maybe an indentation issue or something?
Good luck,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thanks to your advice now I'm almost there! The only part of the script that doesn't seem to work is at the end of the run phase, when I want to clear the canvass and wait for 250ms before moving to the next trial. Any ideas about why the code I wrote is not working?
Thank you again a lot for your help!
Have a nice weekend
Stefano
Hi Stefano,
Yep. self.c.clear() only clears the offline canvas (self.c), but does not update the display. So you would have to do a self.c.show() as well in order to show the cleared canvas (effectively blanking the screen).
Of course, you could also just insert a 250ms blank sketchpad after the inline_script. That would save you the (small) trouble of scripting.
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Ok now I get it, thanks. In the meantime, however, I had already done what you were suggesting, inserting a blank sketchpad after the inline script :-) But thank you so much anyway!
Best,
Stefano