[solved] Inline Python Script Capabilities
I feel that OpenSesame primitives don't expose the functionality I am looking for in the experiment I am developing. However, being able to drop into Python should resolve that, providing the following are possible:
Time logging at various points within an item: I want to show an item with multiple states, which the user advances through by mouse clicks, where I want to record the time spent on each state. (AFAIK, I can't do this with an OpenSesame loop because the number of states available, each time this item is shown, will be variable.) Is it possible to programatically log a time on-demand?
When I have progressed through all the states in said item, I want to then proceed to the next item (which will just be a regular OpenSesame item); again by mouse click. What command is used to advance to the next item?
Will I be able to open a SQLite database from the OpenSesame file pool? I feel like
experiment.get_fileshould do the job -- andimport sqlite3appears to work -- but I'm interested to know if anyone has tried this.
I'm sure I'll have more questions (sorry!)...
Many thanks;
Christopher
Comments
Hi Christopher,
The specific solution would depend on what exactly you want to do, but in general it is very easy to log a timestamp using an
inline_scriptobject. For example:This will create an experimental variable
my_custom_timestampwhich holds the current time.Again, the question is a bit too generic for a specific answer. In general, the way to pause an experiment until a mouse click is to insert a
mouse_responseitem at the point that you want to pause.Sure. OpenSesame uses a regular Python interpreter, so you can use
sqlite3in aninline_scriptitem in the same way as you would in any normal Python script.Good luck with your experiment. As a tip: If you have further questions, please try to be as specific as possible, that way it's easier to give a useful answer!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks, Sebastiaan
My first two queries are related, so let me try to be a bit more specific.
I'm trying to create a self-paced reading task. The way I can see this working is to have a single item that displays successive words, controlled by mouse click. The reason for a single item (rather than multiple; one for each word) is that the sentences will be different lengths and (AFAIK) I can't dynamically create items or control loop variables, on-the-fly. (There are other considerations, such as positioning and various counterbalancing measures, hence preferring to use SQLite to store the data.)
So, let's say the item gets the sentence data as
this| is| my| sentence, where the|delimit the word boundaries. I can easily split this out into a list and then I'd like to show each element, one at a time, then proceed to the next OpenSesame item after the last element is shown. Like so:Where the "double-lined boxes" represent OpenSesame items and the "single-lined boxes" represent screen state.
With regard to the timing, if I use
exp.set('my_custom_timestamp', self.time())on each state change, then that will override the variable. As such, I'd need a different variable for each screen state (presumably I can't create a list here). Would it be possible to instead trigger a logger event programmatically, so that I can store the timestamp into a single variable, but each screen state gets its own line in the output CSV? (Otherwise, my solution would be to "fake" a list by concatenating the time into the same variable and then postprocessing the CSV to deserialise it.)I hope that's more clear. Let me know if I can clarify anything further.
Thanks again
Chris
Hi Chris,
Like you said - each trial you create a list with all the words of a given sentence (e.g. sentence_list = ["this", "is", "an", "example"]). Now, we can run the trial by using a for-loop (in the run-phase of an inline script), where the logic would be something like this:
Hope this helps.
Cheers,
Josh
Thank you, Josh: That's very very helpful
Would I then just call
exp.set('someResponseVar', sentence_responsetimes)after the for-loop? That is, will the list be serialised to a string automatically by the logger, so I get a CSV that looks like (for example):(i.e., the CSV row looks like
"foo","bar","quux","[10,12,9,14]")Thanks;
Chris
No problem
And exactly; you'll have to use exp.set after the for-loop to have the list logged. Of course you could also divide the list into separate columns for each word, by setting separate variables (e.g. word1 word2) instead of the list - but yeah you get the idea.
Good luck and have fun!
Josh
I just tried your code out, Josh and, modulo a few typos, it worked a charm
Thank you again!
For others' sake, the diff on the typos is as follows:
Also, the
mouse_clicked=Falsestatement needs to appear inside the for-loop (e.g., as the first statement), otherwise it doesn't get reset after the first click and cycles through the remaining words in the list instantaneously.Anyway, this is great
Cheers!
Great that you were able to filter out the typo's yourself! I just wrote up something quickly, but should've double-checked at least, I admit