psychopy.org | Reference | Downloads | Github

Possible to access variables in console while debugging?

Dear all,

while debugging in devtools, is there a way to directly access the variables in the script, or maybe even change their values with exp. still running (but paused)?

For example, is it possible to get expInfo[‘participant’] in console while debugging?
Can its value be changed using console and then have an effect on the exp.?

Best wishes,
PJ

print(‘participant’,expInfo[‘participant’]) will show you in the console (it auto translates to console.log)

However, I don’t think you can make changes to the values. I hope you can’t because if you can, then your participants can.

thx for the reply!
however the question remains regarding how to access the value of expInfo[‘participant’]
take another example:

As you can see, expInfo[‘date’] is defined at the beginning of the exp. (actually, let it be any variable that’s defined in the exp.)
but I still haven’t find a way to access them in the console; is that even possible?

by the way, the idea to change value directly is quiet similar to pdb
pdb — The Python Debugger — Python 3.9.5 documentation

it would be really nice to know if something alike could also be applied for psychojs

Hi There:

You can always pass an object to the window by typing:

window.thisObj = thisObj

in a JS code component. Then in developer tools you can type window.thisObj to access it (where thisObj is the name of a component from your PsychoPy experiment).

Thomas pronk has a tutorial on this here if you want to play with this more Thomas Pronk / demo_expose_js · GitLab

Hope this helps!
Becca

In addition to the above, if you access developer tools e.g., by pressing F12 in your experiment, you can add a breakpoint to your javascript code to pause the experiment at that point, e.g., where you define expInfo. Then step through using the buttons highlighted in the image below, and view your variables in the console.

1 Like

hi,
indeed, it worked with window.xxx expose, thx, also on Thomas pronk!
Best
PJ

this is also a valid way to check the values, thx!