Debuggig JS & Version 4.0
Hey Guys,
I have several questions regarding the usage of js_inline_scripts. I first set my experiment (IAT with audio stimuli) up in python (since I'm more fluent in that) and am now in the process of translating it and debugging the translation. Also, I use the 4.0 version since I read here in the forum that there seem to be some seemingly helpful adjustments regarding JavaScript in the new version and general advice to set up new experiments in the new version. Therefor, I also have a few questions regarding the version switch.
At first, my questions regarding the debugging of JS code.
1) Are there general sources you would recommend me for help and advice for this process? I feel like a lot of trouble I'm confronted with comes from OS specifics and not the JavaScript code being wrong per se. Meaning some resources of documentation, summing up OS specifics when it comes to JS would be great (especially when they'd be updated for the new version).
2) Becoming a bit more specific. How and where should I run my experiment to make debugging easiest? I tried running it locally, as I did with the python version. Though at one point when doing a quickrun OS stops opening a "stopped" field although it detects an error and only refers to the console. Afterwards I tried running it in the browser, where different errors occur and are detected. At least in the browser, I receive a proper error message - though one of them isn't particularly helpful (referring to a line in my JS code that does not exist). What kind of debug strategy would you recommend? Running in browsers or running locally and using the console for debugging?
3) Getting more detailed now on JavaScript. Have in mind all questions are in context of the new 4.0 version. One error I receive (i already referred to this one two questions ago), when running the experiment locally from the console, states:
The "occurred online None" - is really giving me a hard time here :D.
4) Second question on my current code. When running the experiment in browser, I receive an error calling that one variable that is referred to in a sketchpad as [blocknumber] does not exist. I do define the variable via: blocknumber = 1
and: vars.blocknumber = blocknumber
in a prior inline_js. So how comes it is not found from the sketchpad? I can imagine that this has something to do with how variables and functions declared in inline_js are transferred between items in OS- though I thought that that would have become more intuitive with the new version, right?
5) Following that error, my browser presents another error found. I guess it occurs because I still have a vars.set() statement in my inline_js which I know does not work. Still, it thought to include this error here because of a detail in the error message, referring to a code line 4137 in my inline_js, although the script only has ~140 lines.
6) Now one question related more the updated in the new version. As said above, the experiment I'm working on was first build locally using inline_python. Yesterday I thought giving the 4.0 OS version a try. But when I try running my stable python version I receive new errors. In my former version, I used a self.sleep()
statement to manipulate time. Now it seems that in the newer version, OS is no more capable of referring to self (it gives me an error stating that). I changed to import time
and time.sleep()
though now my code runs way slower (might also be due to the general update and not this specific line). Can you tell me if/ why the update has precluded the self to be called? And do you have other recommendations other than time.sleep() as alternatives?
Sorry for the very long post and thank you a lot in advance!
Comments
Hi @lt_kn_char ,
The main issue that you're running into is that you're trying to run JavaScript on the desktop through a (Python)
inline_script
item. This won't work! Rather, you need to enter JavaScript into aninline_javascript
item, and then (in OpenSesame 4.0/ OSWeb 2.0) select the OSWeb backend to run the experiment in a browser.The general idea for using JavaScript within OpenSesame is explained here:
I would carefully go through the tutorial and the documentation. That should already clear up many of the issues that you're running into now. And then, once you are familiar with the general procedure, don't hesitate to post further questions here!
-- Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!