Experiment working in 1.5 and not 2.4

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2024.1.5 vs 2024.2.4
Standard Standalone? (y/n) If not then what?: yes

What are you trying to achieve?:
I coded several tasks in the 2024.1.5 version, and I shared these tasks with a colleague using the 2024.2.4 version. The tasks do not work anymore due to an error…
In the task, I had a code element named “language” which is launched during the “Begin experiment”. This code contains the instructions in both french and english:

# Check if expInfo exists and create the language variable
if 'expInfo' not in globals():
    expInfo = {}

# Set default values to English if it is missing from expInfo keys
if 'language' not in expInfo:
    expInfo['language'] = 'English'

# Create the language variable
language = expInfo.get('language')

# Define instructions based on the selected language
if language == "English":
    instructions = {
        'Text_instructions': (
            "Welcome to the task\n\nPress the space bar to continue"
        ),
        'Text_end_task': (
            "This task is now over.\n\nThank you!\n\nPress the space bar to continue"
        )
    }
else:
    instructions = {
        'Text_instructions': (
            "Bienvenue dans la tâche\n\n\Appuyez sur la barre d'espace pour commencer"
            ),
        'Text_end_task': (
            "Cette tâche est maintenant terminée.\n\nMerci !\n\nAppuyez sur la barre d'espace pour continuer"
        )
    }

In another routine, I have a code element pointing to the “language”, and to a Text element to show the text according to the language of the participant (by default, it is in english):

# Set the text for the first set of instructions
InstructionsText.setText(instructions['Text_instructions'])

It works perfectly in 2024.1.5 version, but not in the 2024.2.4.

What specifically went wrong when you tried that?:
I have this error when the task is launched in the 2024.2.4:

InstructionsText.setText(instructions (‘Text_instructions’]).
TypeError: ‘Routine’ object is not subscriptable

I am not sure to understand this error. But it seems that the new version changed the way the routine is handled.
I have created a small experiment with the elements to help reproducing this error:
error.psyexp (23.3 KB)
.

My question is:
Is there a solution to make it work in the 2024.2.4 version?

InstructionsText.setText(instructions[‘Text_instructions’])

instructions is the name of your instructions routine.

You have also used it as a name for your dictionary.

Oh okay! I see it now. Thank you.
I’ll make sure to rename the routine / dictionary so that they don’t share the same name.

That said, I’m still a bit puzzled as to why this worked in version 2024.1.5 but not in 2024.2.4. If there’s a naming conflict, shouldn’t it have caused an error in both versions?

If I may make a suggestion, it would be useful to create an error message about name conflicts. This isn’t the first time I’ve encountered this problem on psychopy (I also plead guilty for bad practice!). But for a beginner like me, the current output errors for these problems were quite confusing, as they didn’t clearly indicate that there was a naming conflict.

Thanks again for your help! :slight_smile: