Changing text mid-routine

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): MacOS Catalina 10.15.4
PsychoPy version v2020.1.2
Standard Standalone? (y/n) y
What are you trying to achieve?: I’m trying to add a block of text where the text changes depending on a condition. I’m building a Corsi block task, and want the text to display ‘Pay attention’ while a sequence of squares is flashing, and ‘Click the squares in order now’ is the sequence of flashing squares has completed.

What did you try to make it work?:
I’ve entered a text component

$feedback9

And a code component with:
Begin routine:

feedback9 = 'Pay attention'

Each frame:

if blkIndex_3 < actualSequenceLength :
    feedback9 = 'Pay attention'
else:
    feedback9 = 'Click the squares in order now'

When the text component is set to constant, I get an error that it isn’t defined. When I set the text component to set every repeat, the text displays, but it doesn’t update. I don’t want to use set every frame, because I want to be able to have this work on Pavlovia.

Any suggestions?

Thanks!!

Can you explain what you mean by this?

You don’t have any choice about where the code goes: if you want it to update at some point during the trial, the code needs to be in the “each frame” tab, otherwise it applies to the entire duration of the trial.

Hi Michael,

My understanding is that ‘set every frame’ doesn’t translate to Javascript/Pavlovia, and hence a workaround is needed.

See p8 of WakeCarter’s crib sheet: https://docs.google.com/document/d/13jp0QAqQeFlYSjeZS0fDInvgaDzBXjGQNe4VNKbbNHQ/edit#heading=h.niu1u15qj037

Cheers,
Josh

Set it to constant but blank.

Update it using feedback9.text=‘Pay attention’ etc. if your text component is called feedback9

However, your each frame code is still updating it every frame. You need to also check its state.

For example:

if blkIndex_3 < actualSequenceLength and  feedback9.text != 'Pay attention':
    feedback9.text = 'Pay attention'
else if blkIndex_3 >= actualSequenceLength and feedback9.text != 'Click the squares in order now'
    feedback9.text = 'Click the squares in order now'

Personally I use a separate variable as a flag for the state of the text component but this should be simpler to understand.

1 Like