psychopy.org | Reference | Downloads | Github

Trail Making Task using colours

I am an undergraduate doing my final year project and part of this includes creating a basic Trail making task where I want the circled numbers 1-8 on screen and my participants have to click each circle in ascending order.
When my participants click the next correct circle in the trail it will highlight and stay green, however if they click an incorrect circle that is next in the trail then that circled number flashes red to tell my participant this is wrong and they would try again with a different number.
Once the final numbered circle in the trail is correctly clicked (highlighted green) I want my routine to end.
Does anyone have any idea how I would start this?

This would take some custom code. Insert a “code component” from the “custom” component tab. In it’s “begin routine” tab, put something like this:

next_number = 1

In its “each frame” tab, put something like this:

# assuming you have named your stimuli consistently like this:

for stimulus in [circle_1, circle_2, circle_3, circle_4, circle_5, circle_6, circle_7, circle_8]:
    
    if mouse.isPressedIn(stimulus) and not stimulus.fill == 'green':
        # check the last character of the stimulus name:
        if int(stimulus.name[-1]) == next_number:
            stimulus.fill = 'green'

            next_number = next_number + 1
            if next_number == 9:
                continueRoutine = False

            break
        else:
            stimulus.fill = 'red'

That won’t flash the stimulus red temporarily, but it should get you started on the right path.

Hi,

Thank you for your reply.

I have implemented the above code, however when I come to run the experiment it crashes when I click any stimuli on screen and it does not fill the stimuli with the specified colour

Please provide the error message so we can see what goes wrong.

Hello,

I have been assisting them with this, I’ve fixed the crash. However I am unable to fix the second issue. When we press any stimuli, regardless of if it is correct or not it turns red. If I remove the end bit of code (else stimulus.fill = red) then selecting the correct answers does turn them green.

I am not much of a coder and was wondering about the bit of the code which checks the last number in the name. If we were to go into double digits, would we change this to [-2,-1] or something similar?

Thank you for the help

That sounds like the code isn’t correctly indented - white space is semantic in Python. In the code above, each level of indenting corresponds to 4 spaces.

Insert some (TEMPORARY) debugging code at each stage to check if the values are what they are expected to be. e.g. sprinkle in some print statements at various points:

if mouse.isPressedIn(stimulus) and not stimulus.fill == 'green':
    # TEMP:
    print(stimulus.name[-1])
    print(next_number)

    # check the last character of the stimulus name:
    if int(stimulus.name[-1]) == next_number:
        stimulus.fill = 'green'
        # etc

[-2:] will give you the last two characters.

I put in the print codes, so I was expecting 16 values (8 presses*2) going 1223 etc. What I got instead was:
1
1
1
2
1
2
1
2
1
2
2
2
2
3
2
3
2
3
3
3
3
4
3
4
3
4
3
4
4
4
4
5
4
5
4
5
4
5
5
5
5
6
5
6
5
6
6
6
6
7
6
7
6
7
7
7
7
8
7
8
7
8
7
8
7
8
8
8

I checked the indentations and can’t see anything untoward.

Please show us the actual code you are using:

There is some additional code in this as I am also trying to record all mouse clicks

In Begin Routine:

next_number = 1
clicked_stim =[]

In Each Frame:

for stimulus in [circle_1, circle_2, circle_3, circle_4, circle_5, circle_6, circle_7, circle_8]:
    
    if mouse.isPressedIn(stimulus) and not stimulus.color == 'green':
        # check the last character of the stimulus name:
        print(stimulus.name[-1])
        print(next_number)
        if int(stimulus.name[-1]) == next_number:
            stimulus.color = 'green'

            next_number = next_number + 1
            if next_number == 9:
                continueRoutine = False

            break
        else:
            stimulus.color = 'red'
if mouse.isPressedIn(stimulus):
    clicked_stim.append(stimulus.name)