Pavlovia error : Failed to resolve module specifier "psychopy"

Hey @JensBoelte,
To be honest, I think I put it in each frame based on what ChatGPT suggested (I had many issues coding this experiment before uploading it to Pavlovia). Yes, the “v” or “f” keypress ends the routine, allowing the participant to proceed to the “feedback” routine. I did not define the correct key in my condition file because it depends on what the participant enters in the “infoimc” routine.

In short, each participant has to input their BMI, and based on their BMI, the code calculates BMI+5 as “Imcpercu.” This variable is then used to determine correct or incorrect responses by comparing it to the BMI of the presented silhouette. However, I believe the issue in Pavlovia is that “imcperçu” is being treated as “null”…

Anyway, here is the code!

infoimc routine :
→ Begin experiment :
win.mouseVisible = True

IMCpercu = None
delta = 5

→ End routine


try:
    # Récupération du texte de la textbox et conversion en float
    IMCpercu_text = textbox_IMC.text  # Récupère le texte de la textbox
    IMCpercu = float(IMCpercu_text)  # Convertit en float

    # Vérifie que l'IMC perçu est positif
    if IMCpercu <= 0:
        raise Error("Les valeurs doivent être positives.")

    thisExp.addData('IMCpercu', IMCpercu)

except Error as e:
    print(f"Erreur de conversion : {e}") 
    IMCpercu = None 

Essai routine :
→ Begin routine :

# Calculer le seuil de l'IMC cible basé sur l'IMC perçu
imc_target = IMCpercu + delta

# Déterminer la réponse correcte en fonction de la condition
if condition == "plus_élevée":
    correct_response = 'v' if stim_imc > imc_target else 'f'  # Comparaison avec l'IMC cible (IMC perçu +5)
elif condition == "plus_faible":
    correct_response = 'v' if stim_imc < imc_target else 'f'  # Comparaison avec l'IMC cible (IMC perçu +5)

# Enregistrer la réponse correcte attendue
thisExp.addData('CorrectResponse', correct_response)

# Afficher les valeurs pour vérification
print(f"IMC perçu: {IMCpercu}, IMC cible: {imc_target}, IMC silhouette: {stim_imc}, Condition: {condition}")
print(f"Réponse correcte: {correct_response}")

→ Each frame :

keys = event.getKeys(keyList=['v', 'f'])  # 'v' pour vrai, 'f' pour faux

if keys:
    participant_response = keys[0]  # Première touche pressée
    # Vérifie si la réponse est correcte
    if participant_response == correct_response:
        feedback_message = 'Bonne réponse !'
        reinforcement = "positif"
    else:
        feedback_message = 'Mauvaise réponse.'
        reinforcement = "négatif"

    # Enregistre la réponse dans les données
    thisExp.addData('ParticipantResponse', participant_response)
    thisExp.addData('Reinforcement', reinforcement)

    continueRoutine = False  # Passe à l'essai suivant

Feedback routine :
→ Begin experiment : progress = 0.5

→ Begin routine :



# Déterminer le feedback à afficher
if reinforcement == "positif":
    feedback_text.setText("Bonne réponse!")
    feedback_text.setColor('green')
    progress = min(progress + step, 3.0)  # Limite à 100%
    barColor = "green"
elif reinforcement == "négatif":
    feedback_text.setText("Mauvaise réponse.")
    feedback_text.setColor('red')
    progress = max(progress - step, -3.0)  # Limite à 0%
    barColor = "red"

# Afficher les éléments (affichage automatique activé)
feedback_text.setAutoDraw(True)

→ Each frame :

if feedback_clock.getTime() >= feedback_duration:
    feedback_text.setAutoDraw(False)
    continueRoutine = False  # Arrêter la routine après 2 secondes

You appear to be using event.getKeys in a code component which ends the routine, so I would recommend that you replace it with a normal keyboard component.

You also have unnecessary code in your feedback routine. Why not use a text or textbox component?

What are your print statements telling you about IMCpercu?

I hope I will be answering correctly !
I replaced event.getKeys ! Do I need to put every eliffollowing if len(keys)?

I’m not sure which part of the code is unnecessary… I do have a text component for the feedback, but what is written and its color depend on my code…

In the “Infoimc” routine, I use it to check if there’s an error when the participant enters their BMI in the textbox.
In the “Essai” routine, it helps me verify if the values are correct.

Try

infoimc routine :
→ Begin experiment :
win.mouseVisible = True

IMCpercu = None
delta = 5

→ End routine

try:
    # Récupération du texte de la textbox et conversion en float
    IMCpercu_text = textbox_IMC.text  # Récupère le texte de la textbox
    print('IMCpercu_text',IMCpercu_text)
    IMCpercu = float(IMCpercu_text)  # Convertit en float

    # Vérifie que l'IMC perçu est positif
    if IMCpercu <= 0:
        raise Error("Les valeurs doivent être positives.")

    thisExp.addData('IMCpercu', IMCpercu)

except Error as e:
    print(f"Erreur de conversion : {e}") 
    IMCpercu = None 

Essai routine :
→ Begin routine :

# Calculer le seuil de l'IMC cible basé sur l'IMC perçu
imc_target = IMCpercu + delta

# Déterminer la réponse correcte en fonction de la condition
if condition == "plus_élevée":     
    if stim_imc > imc_target:
        correct_response = 'v'
    else:
        correct_response = 'f'  # Comparaison avec l'IMC cible (IMC perçu +5)
elif condition == "plus_faible":
    if stim_imc < imc_target:
         correct_response = 'v' 
    else:
         correct_response = 'f'  # Comparaison avec l'IMC cible (IMC perçu +5)

# Enregistrer la réponse correcte attendue
thisExp.addData('CorrectResponse', correct_response)

# Afficher les valeurs pour vérification
print(f"IMC perçu: {IMCpercu}, IMC cible: {imc_target}, IMC silhouette: {stim_imc}, Condition: {condition}")
print(f"Réponse correcte: {correct_response}")

→ End Routine:

if key_resp.corr:
        feedback_message = 'Bonne réponse !'
        reinforcement = "positif"
        progress = min(progress + step, 3.0)  # Limite à 100%
        barColor = "green"
else:
        feedback_message = 'Mauvaise réponse.'
        reinforcement = "négatif"
        progress = max(progress - step, -3.0)  # Limite à 0%
        barColor = "red"

# Enregistre la réponse dans les données
thisExp.addData('ParticipantResponse', key_resp.keys)
thisExp.addData('Reinforcement', reinforcement)

Feedback routine :
→ Begin experiment : progress = 0.5

→ Begin routine :


# Déterminer le feedback à afficher


→ Each frame :

[/quote]

I tried it, but unfortunately, it does not work because my feedback bar does not move and stays red. Moreover, the progress text remains “”, just as I wrote in the component.

The relevant parameters for the components need to be set to update every repeat.

Unfortunately it still doesn’t work. Unless I need to set every repeat things in “essai” routine ?

At this point I think you need to show what you’re trying, including the components.

Ok ! Here is the “essai” routine components:

I have not set anything here to “set every repeat”, the keyboard accepts “v” and “f” and ends the routine and it is set as constant.

Here is the feedback routine :


The feedback text looks like this :

I have updated the color to “set every repeat”.
Same for the bar with size and color. The progress_text still the same every trial.

Thank you for your time !

Put $feedback_message at the text in the feedback text component.

1 Like

Thank you, the message does appear, but it always displays a bad answer. The bar also remains red and does not empty when a bad answer is given.

You have a keyboard component called vrai_faux. My code assumed it was called key_resp. I imagine you haven’t set the correct answer in it either.

The logic code component might need to move to the top.

If something isn’t working then you need to show how you are trying to make it work. Have you set the colours in the components?

Yes, I already replaced it by “vrai_faux”.
Here is the relevant parameters of the components :
→ Feedback_text : $feedback_message
→ Bar properties :


Update: I haven’t changed anything, but the core functionality is now working on Pavlovia. The only remaining issue is that the feedback bar is not updating correctly on each trial—it doesn’t “remember” its previous position and only shows negative feedback.