set allowed responses for touch_response item while keeping timeout option
Hi there,
I'm trying to make a simple Go/NoGo- Task for android devices. I've already read that there's currently no option to set allowed responses for a touch_response item. My intention is to make the participant wait until a timeout of 2 sec is over in case of NoGo trails and to tap a certain part of the screen and continuing immediately with the next trial in case of GoTrials. That worked out fine so far.
The problem ist, that the next trial does not only appear when the correct_response is given but also when there's a tap on any other part of the screen. In case of any trials, I want any other responses to be ignored AND I want to keep the timeout for any trial UNLESS there is a correct response in case of a GoTrial.
I've already tried to solve this by adding an inline_script following the description in this discussion:
http://www.cogsci.nl/forum/index.php?p=/discussion/1030/solved-restricting-allowed-choices-in-touch-response-not-possible/p1
but I couldn't manage to keep the timeout option for the previous touch_response item. The above inline_script makes OpenSesame crash as soon as I give a response which isn't allowed instead of ignoring it.
I'd be really glad if someone had a solution for this
thanks,
Sophie
Comments
Hi Sophie,
The discussion you linked us to was probably written with an older version of Opensesame. Can you post the error message of the crash you encountered? MAybe you can share your current version with us, so we can debug together?
At any rate, the solution would probably look like this (conceptually)
Does it help?
Eduard
Thanks for your response, Eduard!
I am using OpenSesame 3.1.4 Jazzy James.
I tried to copy your solution into an inline script right after the touch response item and after doing so, I got the following error message:
Stopped
The experiment did not finish normally for the following reason:
Failed to compile inline script
Details
code: while timeout not reached:
item-stack: experiment[run].experimental_loop[run].block_sequence[run].block_loop[run].trial_sequence[prepare].new_inline_script_3[prepare]
exception type: SyntaxError
exception message: invalid syntax (, line 2)
item: new_inline_script_3
time: Sat Dec 10 14:59:52 2016
phase: run
line: 1
Traceback (also in debug window)
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\inline_script.py", line 73, in prepare
self.var.get(u'_run', _eval=False))
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\python_workspace.py", line 147, in _compile
return compile(script, u'', u'exec')
File "", line 2
while timeout not reached:
^
SyntaxError: invalid syntax
Hi Sophie,
The script Eduard suggested is not actually a working script, but rather a concept of what such a script should look like ('pseudocode').
Could you provide the original error code that occured before you added the new inline script?
Best,
Laurent
Hello Laurent,
here is the inline script that I previously used:
allowed_responses = [26]
while self.get('response') not in allowed_responses:
exp.items['touch_response'].run()
The "correct response button" ist on position 26 (I divided the screen into 9 rows and 3 columns).
This is the error message I got:
Stopped
The experiment did not finish normally for the following reason:
Error while executing inline script
Details
item-stack: experiment[run].experimental_loop[run].block_sequence[run].block_loop[run].trial_sequence[run].new_inline_script_3[run]
exception type: AttributeError
exception message: _flush not found
item: new_inline_script_3
time: Mon Dec 12 12:21:07 2016
phase: run
Traceback (also in debug window)
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\inline_script.py", line 102, in run
self.experiment.python_workspace._exec(self.crun)
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\python_workspace.py", line 161, in _exec
exec(bytecode, self._globals)
File "", line 4, in
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\mouse_response.py", line 128, in run
if self._flush:
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item.py", line 238, in getattr
raise AttributeError(u'%s not found' % var)
AttributeError: _flush not found
Hi Sophie,
The inline script you used is written in an older version of OpenSesame. Would it help if you changed it to
Note that the method of referring to variables has changed, no need to use self.get('variable') anymore. The error message probably occured due to older code. Let me know if it works!
Best,
Laurent
Hi Laurent,
I changed the inline script and now it says the following:
Stopped
The experiment did not finish normally for the following reason:
The variable 'response_touch_response' does not exist. Tip: Use the variable inspector (Ctrl+I) to see all variables.
Details
item-stack: experiment[run].experimental_loop[run].block_sequence[run].block_loop[run].trial_sequence[run].new_inline_script[run]
time: Mon Dec 12 14:09:10 2016
Do I have to replace "response_touch__response" with another (actual) variable from my experiment?
Hi Sophie,
Yes, my bad. That is the name of the variable i just used to check it. Your should replace
var.response_touch_response
withvar.response_[name of your variable]
ok, thanks
I think it works now. The only problem is, that now, I'm stuck with the current item when not giving the right response instead of continuing as soon as the timeout is over.
Hi Sophie,
Did you work this problem out yet? If not, it might be an idea to replace the
loop
described above with some other loop that keeps track of time. And instead of running the touch-response item repeatedly after an erroneous error, have the program stop momentarily ('sleep') and wait for the timeout:Before the
touch_response
item, add aninline_script
where, in the run-phase, you stateThen, after the
touch_response
item add the following to your script:This should avoid being stuck with the same item over and over again. Depending on what you want to measure and how you want to provide feedback you can split this loop for Go and NoGo trials. Furthermore, you could assign variables (e.g.
var.correct_answer
) within the loop to check for correct and incorrect answers and possibly display feedback based on the answers.Disclaimer: i don't have a tablet available at the moment so i haven't checked how it behaves on an actual touch-screen. Good luck!
Best,
Laurent
it works perfectly fine this way! Thank you very much!