Resources for translating Python to JavaScript
Hi!
I currently have a working experiment in OpenSesame with Python inline code. However due to the pandemic going on, it's best if we run the experiment online. Therefore I want to use the OSweb functionality.
For this I of course have to translate my Python inline code to JavaScript code. I don't have any experience with the latter. Are there any good resources on translating Python to Javascript?
I did see that there was another thread about translating Python to Javascript currently on the forum, but that one was very specific, so I thought I would ask more generally.
Also is there a list of all the things that are NOT possible in JavaScript somewhere? The webpage about Javascrip (https://osdoc.cogsci.nl/3.3/manual/osweb/javascript/) basically says, "Canvas, Keyboard objects, etc", but I'm not sure if the "etc" are a few more things, or are a whole lot of things that will make it impossible in the first place to translate the script.
I personally need at least some randomization, a dataframe (now using pandas in Python) and a form.
I hope anyone can help and kind regards in advance!
Sanne
Comments
Hi Sanne,
I'm not an expert in JS myself yet, but in general I think there's the following rule of thumb: interaction between the GUI (
sketchpadsetc.) and thejava_inlinescriptis only possible by storing and retrieving variables with thevars.object, as described here:More advanced ways of communication between script and GUI, such as running items from the GUI via an
java_inlinescript, or readinglooptables withdatamatrixare not possible. Also, as you mentioned yourself, Python classes such asCanvas,Keyboard,Mouse,Samplerdo not have a JS equivalent yet.Unfortunately,
formitems are also not supported by OSWeb yet. Instead, you will have to usesketchpaditems combined withmouse_responseorkeyboard_responseitems to show questionnaires and collect responses. Perhaps this discussion can be of help:Randomization and reading in dataframes should be possible in JS, although I don't know how, from the top of my mind. I can look into this, if wanted.
Good luck and let us know if you need more specific help!!
Cheers,
Lotje
Did you like my answer? Feel free to

Hi @Sannee , me again. To shuffle/ randomize you could do something like described here:
Did you like my answer? Feel free to

Hi Lotje,
Thank you so much for your clear answer!
Sadly enough most of my experiment is build on a form, so I think I'd either have to rebuild the entire experiment from the ground up then or find another way to distribute it. (although that is also on me, I should have checked before I started building)
Is there any other way to let an OpenSesame experiment run remotely without others having to install OpenSesame themselves?
Kind regards,
Sanne
Hi Sanne,
On windows systems, I used to simply download the
zipfile of Opensesame from github, extract it, and then started Opensesame by double clicking on the.exefile. Like that no installation was necessary (which was my way of bypassing not having adminstrator rights on our lab computers, while not messing up the entire system). However, last time I checked it was 3 years ago. No guarantee that it still would work like that. I also have no clue whether something comparable exists for Mac/Linux systems.If you have Windows, you can try yourself:
1) Go to Github, pick a version, download the zip and extract
2) Find the opensesame.exe file in the folder and execute it
Hope this helps,
Eduard
Hi!
Thanks for the suggestion! It works fine for some people I tested it with, but not for others sadly.
It seems like, if there is already an older version of Python on the computer, OpenSesame will run with that version of Python and then crash because some functionalities aren't there yet.
Kind regards,
Sanne
Hi!
I had one more question about JavaScript and its functionalities. I've seen the survey templates that have been uploaded, but is there any way to create text boxes that people can fill in values in with a Javascript/Sketchpad combination?
Kind regards,
Sanne
Hi Sanne,
Not sure whether this is what you mean, but there is a osweb version of the text input funcionality (users type in responses that are longer then a single character). See this discussion for example experiments:
I think there are also other discussion around that deal with that issue. Perhaps you could browse a little if this link doesn't help you.
Good luck,
Eduard
Hi Eduard,
This does indeed seem to be exactly what I'm looking for! Thank you so much!
Kind regards,
Sanne