Corsi Task - ReferenceError: currBlockName is not defined

URL of experiment: corsi [PsychoPy]
Leonardo Bernardino / corsileo · GitLab

Description of the problem: I’m using a version of the Corsi blocks task with a 4 x 4 grid of blocks to click on (downloaded from experiments’ page). So, I’m using Builder as I don’t have skills to code :frowning:
It works in my computer (PsychoPy 2020.2.10), but when I try to run online, I get this error message.

There’s a code component (updateBlocks) with the following properties:

Begin Routine

# initial state
blkIndex = 0
nextSwitch = blockDuration
doingResponse = False
currBlock = None

# store blocks as a dictionary (to switch between name/object)
blocks = {}

for blockName in blocks:

Each Frame

if not doingResponse and t > nextSwitch:
if currBlock is not None:
    #reset color of current block
    currBlock.color = 'white'

# then change current block and make that red
if blkIndex >= len(sequence):
    doingResponse = True  # no more blocks to show
    currBlockName = sequence[blkIndex]
    currBlock = blocks[currBlockName]
    currBlock.color = 'red'

    # track time of this change
    nextSwitch += blockDuration
blkIndex += 1

 # all clicked?
if len(mouse.clicked_name) >= len(sequence):
continueRoutine = False

# update color of clicked
for blockName in mouse.clicked_name:
blocks[blockName].color = 'darkgrey'

Anyone could help me? Thanks in advance

As per my crib sheet if you have a variable that is set within a clause you need to give it a default value first.

Thank you very much, @wakecarter!
I read the crib sheet, but I don’t know much about code. So, where do I have to add the default value and how to do it exactly? Thanks again!

currBlockName = "" in Begin Experiment is the easiest method.

Thank you so much, @wakecarter!
It solved the error, but another one appeared:
“TypeError: Cannot set property ‘color’ of undefined”. I read others posts and your crib sheet, but I can’t update to 2021. Do you know how can I fix it?
Thanks in advance!

Where is sequence defined?

I have a 2020 crib sheet too.

The sequence is defined in this file
conditions.xlsx (10.0 KB)

Try print(sequence) here.

It might be that you need to put eval(sequence) in the JS only.

Ref: List values in spreadsheets - #4 by arnon_weinberg

What I do in my self paced reading demo is split the input by spaces.

It still doesn’t work, but I’m trying to fix it :slight_smile:
Thanks a lot, @wakecarter!