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