| Reference | Downloads | Github

In coder properties of Builder, can I designate trigger loop for only correcrt answers?

This is related to the previous question about the trigger problems on correct answers.
I inserted into code properties,

if response.corr == 1: parallel.setData('$p_port_1)

else: parallel.setData(99)

p_port_1 is a column name indicating trigger numbers in the condition file included in loop.
And only 99 appeared when I try the test experiment.

My first problem is $p_port_1 doesn’t work in the code properties, although when I use parallelOut properties, it works.
Of course I can use parallelOut properties and would know the valid segments by comparing the stored correct answer results, but I’d like to do a bit easier.

  1. How can I present $p_port_1 using parallel.setData()? $variables instead of values didn’t work? If other codes are needed, please let me know.
  2. Are there any solutions mark triggers only correct responses in parallelOut properties?
  3. Or if the right answer is “m” in the keyboard, I thought;

if response.keys == m:

but it didn’t work :sob:
Please some help.
Thank you always.


  1. You don’t need to use the $ symbol in Python code. That is just there in other parts of psychoPy to indicate that something should be interpreted as Python rather than a literal value. In a code component, everything is code by definition, so $ signs can cause errors.

  2. Your code above isn’t formatted to show indentations properly, but it should look like this:

if response.corr == 1:

The fact that 99 does appear shows that at least your parallel port is working. So the problem may be that response.corr never evaluates to 1. You’ll need to check that aspect of whether correct responses are detected at all before worrying about the parallel port.

When checking the keyboard, .keys returns a list rather than a single value (notice it’s a plural). So to check it, you have to look for a single entry in the list. Also note that you aren’t surrounding m in quotes, so it is being compared to a variable called m (that probably hasn’t been defined), rather than the literal value 'm'. e.g.

if 'm' in response.keys:

Lastly, instead of saying "but it didn’t work :sob: ", please give us actual error messages or describe exactly what went wrong, so we don’t have to guess.

Thank you for the advice.
Actually there’s no error messages and ran well.
It just didn’t appear trigger marks on the recording program.

I thought since correct responses present on the response.corr column as 1 or 0,
if response.corr == 1: would work.
I think I have to try other ways.
Thanks again.

I solved this problem.
It worked I typed the codes in “Each Frame” section not in “Begin Routine” section.