Progress/Feedback bar using a polygon

Hi,
I am currently developing an experiment that involves a training procedure, and I need to show correct or incorrect answers using a gauge. The issue I’m encountering is that my progress bar does not fill up completely or decrease with each correct or incorrect response. Instead, it only has three positions. Ideally, after each trial, the bar should take the last position and either increase or decrease by a specific step, resulting in a new position.

I am using PsychoPy version: v2014.1.5.

Any advice or help would be greatly appreciated!

Here is my code in Begin routine :

progress = 0.5
step = 0.05

Barre de progression

bar = visual.Rect(win, width=progress, height=0.1, pos=[0, 0], fillColor=“gray”, lineColor=None)

Texte explicatif

progress_text = visual.TextStim(win, text=“Progression”, pos=(0, 0.15), color=“black”, height=0.04)

Déterminer le feedback à afficher

if reinforcement == “positif”:
feedback_text.setText(“Correct !”)
feedback_text.setColor(‘green’)
progress = min(progress + step, 1.0) # Limite à 100%
bar.fillColor = “green”
elif reinforcement == “négatif”:
feedback_text.setText(“Incorrect !”)
feedback_text.setColor(‘red’)
progress = max(progress - step, 0.0) # Limite à 0%
bar.fillColor = “red”

Afficher les éléments (affichage automatique activé)

feedback_text.setAutoDraw(True)
progress_text.setAutoDraw(True)
bar.setAutoDraw(True)

Durée du feedback

feedback_duration = 2.0
feedback_clock = core.Clock()
feedback_clock.reset()

And here is my code in Each Frame :

Mise à jour de la largeur de la barre à chaque frame

bar.width = progress * 1.0 # La largeur de la barre est définie par la progression

Dessiner les éléments à chaque frame (la barre, le texte, etc.)

progress_text.draw() # Dessiner le texte explicatif
bar.draw() # Dessiner la barre de progression

Fin du feedback après le délai spécifié

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

Is all of this code in Begin Routine? You seem to be resetting the variables and recreating the polygons every time.

Some of it is in Each Frame, starting from bar.width = progress * 1.0.
I tried using a new variable to avoid creating polygons every time, but it didn’t work.

Either create the bar in Begin Experiment or create it as a Builder component. The latter is easier if the size only changes during one routine.

Are you using Builder?

Yes, the bar is a polygon component in the Builder. However, using this component alone, I am unable to make it dynamically change on each trial based on correct or incorrect responses, right ?

Is this your code or created by the Builder component?

Polygon sizes can be changed dynamically Each Frame either by setting a variable or

or using code:

polygon.setSize([newX,newY])

This is part of my code.

Should I specify something particular in the “Layout” section of my component? I’ve updated it to set every frame (thank you!), but I’m unsure what to enter in the “size” field.

Start by getting rid of any code related to bar.

Set the bar component fill colour to $barColor updating every frame.
Set the bar component fill colour to [progress,.1] updating every frame.

Change bar.fillColor = “green” to barColor = “green”
Change bar.fillColor = “red” to barColor = “red”

Is progress_text a text component and a text object created in code?

Thank you! I might have made a mistake here because I get the following error message:

bar.setFillColor(barColor[progress,.1], log=False)  
TypeError: string indices must be integers  
# Experiment ended with exit code 1 [pid:15452] # 

Yes, progress_text is a text component, but it is also created in the code. However, it works fine!

Sorry – my mistake

Set the bar component fill colour to $barColor updating every frame.
Set the bar component size to [progress,.1] updating every frame.

I would be interested to understand why you are creating the same text object in two different ways? Whichever gets created second will be replacing the first version.

Thank you!

However, the bar still takes only three positions instead of continuously adjusting. If I get several correct answers in a row, it should increase significantly, but that is not happening.

Regarding the progress_text, I initially wrote the code first and then used the Builder, thinking I needed to link something from the code to a Builder component. In the end, I removed its part from the code and kept only the component, which now works perfectly!

If thew bar can only have three sizes and the size is [progress,.1] then please show any code related to progress, clarifying which tab the code is in. Unless told otherwise, I will assume that the code is at the top of the same routine as the bar.

In begin routine, I set the progress as 0.5 progress = 0.5
Same, in begin routine, if the reinforcement is positive, I use progress = min(progress + step, 3.0) ; but if the reinforcement is negative, I use progress = max(progress - step, -3.0). I want limits between which the bar can go.

I don’t have anything related to progress in Each Frame.

If progress is supposed to be set only once per routine then put progress = 0.5 in Begin Experiment so you don’t reset every trial and the bar size (and fill colour) can update every repeat instead of every frame.

Thank you so much it works !!