srbox inline script
Hi! I'd like to use an srbox in an inline script.
However, if I use the code from here https://osdoc.cogsci.nl/3.3/manual/response/srbox/#function-srbox__init__experiment-devnone in this way:
import srbox
srbox.__init__(experiment, dev = COM1)
t0 = clock.time()
srbox.start()
button, t1 = srbox.get_button_press(allowed_buttons=[1,2],
require_state_change=True)
if button == 1:
response_time = t1 - t0
print('Button 1 was pressed in %d ms!' % response_time)
srbox.stop()
I get the following error:
name 'experiment' is not defined.
If I delete the line:
srbox.__init__(experiment, dev = COM1)
then I get the following error:
'module' object has no attribute 'start'.
I would appreciate any help to solve this issue. Note that this is a very "plain" experiment aimed to do nothing more than get the srbox to work.
Comments
Hi @Paula ,
These two lines:
Are not necessary, because the srbox is initialized by the srbox plugin. This means that, as soon as you have this plugin in your experiment, an srbox object will exist and can be used as in the example scripts in the documentation. In other words: simply removing these two lines should do the trick!
-- Sebastiaan
PS. Even if you would need to initialize the object, this would not be the way to do it. If you want to understand how the
__init__()function etc. work, then I have a few videos about the basics of object-oriented programming. 😊Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi @sebastiaan
Thanks for the reply! I'd much rather use the plugin (I've used it before and it works perfectly), but I want to integrate this inline script in a coroutine. The plugin doesn't seem to work in the coroutine (I've tried without success).
I've also tried removing the lines you mention are not necessary, and I get the error message:
'module' object has no attribute 'start'.I upload the experiment I am working on here, and now I get the following error:
name 'srbox' is not definedThank you for the link to the videos on programming! I will investigate further!
Hi @Paula ,
Even if you're going to use the
srboxprogrammatically, you still have to add the plugin to the experiment. If necessary, you can simply put it at the top of the experiment and then set the timeout to 0 so that it effectively does nothing. But the plugin needs to be there, otherwise thesrboxobject will not be available in the Python workspace!— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Sorry @sebastiaan , I didn't explain myself clearly:
even when the plugin is added I still get the error message
name 'srbox' is not definedThe experiment is nothing more than a welcome sketchpad, the srbox plugin, and the inline code, and the exit sketchpad.
@Paula Ah, I see. That's because the plugin is in dummy mode, in which case the
srboxobject is not created. There is currently no way to test thesrboxin dummy mode in a script, I'm afraid! In other words: you'll have to get a physical SR Box to develop and test the experiment.(I'll update the documentation to indicate this, because that's indeed not obvious.)
Check out SigmundAI.eu for our OpenSesame AI assistant!
@sebastiaan : Thank you VERY much for clarifying this!! I really appreciate your help!