The same trigger is sent for both non-responses and incorrect responses

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): v2021.2.3
Standard Standalone? (y/n) If not then what?: y
**What are you trying to achieve?:
I want to differentiate the triggers sent for incorrect and non-responses for the Stroop task. My code successfully sends the specified trigger to the recorder for correct responses, but the problem is that although I have coded to send different triggers for incorrect and non-responses, the same trigger is sent in both cases. We are using the brainVision system. The code below is what I have written in “each frame” section:

 if resp.corr == 0:
            if resp.keys !='None':
                resp.corr = 2
            else:
                resp.corr= 0
        if (resp.keys == str(corrAns)) or (resp.keys == corrAns) and not mark_started:
            port.write([0x10]) 
            mark_start_time = globalClock.getTime()
            mark_started = True
        elif resp.corr == 2 and not mark_started:
            port.write ([0x03]) # Sends S3 trigger
            mark_start_time = globalClock.getTime()
            mark_started = True
        elif resp.corr == 0 and not mark_started:
            port.write ([0x04]) # Sends S4 trigger
            mark_start_time = globalClock.getTime()
            mark_started = True
            
        if mark_started and not mark_ended:
            if globalClock.getTime() - mark_start_time >= 0.005:
                port.write([0x00])
                mark_ended = True

The first 5 lines, differentiates the incorrect and non-responses. I checked the csv output file and this code does what I need.
The problem has to do with elif parts of the code. It only sends S4 trigger for both the incorrect and correct responses. This happens even if I comment out the second elif codes. But, If I, for example, shut down the computer and turn it on and comment out the second elif codes and run the experiment, it will send S3. This time when I uncomment the second elif, it will only send S3 trigger for both cases. This shows that the problem originates from somewhere else.

What did you try to make it work?:
I have tried to differentiate the incorrect and non-responses in other ways, but they did not work.

I would be grateful if you could help us with this problem.
Thank you.

Hello,

intendation is importang in python So is it a copy and paste error or intended?

if resp.corr == 0:
    if resp.keys !='None':
        resp.corr = 2
    else:
        resp.corr= 0
        if (resp.keys == str(corrAns)) or (resp.keys == corrAns) and not mark_started:

So the if is actually inside the else.

or did you want this:

if resp.corr == 0:
    if resp.keys !='None':
        resp.corr = 2
    else:
        resp.corr = 0
if (resp.keys == str(corrAns)) or (resp.keys == corrAns) and not mark_started:

Also holds for the second if.

Best wishes Jens

Hi. Thank you for your reply. Sorry, I didn’t see that when I pasted the code here. It is a copy paste error. It is correct in the original code.

Hi Psychopy experts,
We would be grateful for any help with this issue as we have not been able to resolve it yet.
Thank you.

Dear Dr. Peirce @jon,
I am still trying to solve this problem, but had not much success in the last two weeks. I would be grateful if you could help me with that. Should you need any more information please let me know and I will share it here.
I would like to appreciate your time and consideration.
Best,
Kianoosh