Hello everyone!
Today I would like to share a very minor inconvenience I encountered while writing Python code in the Code Component and autotranslated to JS with the code type option “Auto → JS”. I am using Psychopy 2024.2.4 for Windows 11 x64 with Python 3.8.
I am currently (still, don’t ask why) writing code for a go/no-go task. I created a code component which features an instruction text appearing at the beginning of the experiment.
Since this experiment has two possible counterbalancing routines (the “go” color can be either blue or yellow), the text needs to be formatted to display the correct color for each “go” and “nogo” condition based on the counterbalancing type. To see how to include text formatting in Psychopy, look up this tutorial. Here’s how mine looks like:
inst = "Welcome!\n" \
"In this task you will always see a %s or %s square.\n" \
"Your task each time is to press \"J\" as quickly as you can whenever you see a %s square.\n"\
"Since you need to respond within half a second, you will have to be very quick!\n"\
"Be careful! When you see a %s square, you should NOT press the key." \
"In this case, you just wait until the next square appears.\n"\
"You have to respond as QUICKLY and as ACCURATELY as possible.\n"\
"Press the SPACEBAR to continue." %(goCol, nogoCol, goCol, nogoCol)
So far so good. However, the autotranslated JS code looks like this:
inst = `Welcome!
In this task you will always see a ${goCol} or ${nogoCol} square.
Your task each time is to press "J" as quickly as you can whenever you see a ${goCol} square.
Since you need to respond within half a second, you will have to be very quick!
Be careful! When you see a ${nogoCol}`
;
As you can see, the text string is interrupted when the last formatted string is inserted.
When I pilot my experiment in Runner, the text displays correctly, including the formatted fields.
Again, I don’t think this is a major problem. I shared this in case someone who doesn’t have much coding experience like myself fears there is some hidden syntax error/mistake.
Cheers!