Text component dictated by values in excel procedure file not working

OS (e.g. Win10): Win11
PsychoPy version (e.g. 2024.2.4 Py 3.8): 2024.1.5
Standard Standalone Installation? (y)
Do you want it to also run online? (y)

What are you trying to achieve?:

I have a self-timed reading task where participants hit space when they have read a chunk / segment of a story. There are many stories in the procedure file, which are allocated by the variable ‘Code_practise’ in the procedure file. For each story, there are two versions. The version the participant sees depends on their experimental group, allocated by the variable ‘condition’ which is set by a coin toss at the start of the experiment.

The story is displayed one chunk at a time - to do this I have the following code:

# assemble whole story & note which chunk is crit chunk

story_practise = ""
n_chunks_practise = 0
current_chunk_practise = 0
chunks_practise=[]

# every story has a context
story_practise = Context_practise

if Number_of_pre_sentence_chunks_practise == 0:
    n_chunks_practise = 1
elif Number_of_pre_sentence_chunks_practise == 1:
    story_practise += "\t" + Pre_sentence_chunk1_practise
    n_chunks_practise = 2
elif Number_of_pre_sentence_chunks_practise == 2:
    story_practise += "\t" + Pre_sentence_chunk1_practise + "\t" + Pre_sentence_chunk2_practise
    n_chunks_practise = 3
elif Number_of_pre_sentence_chunks_practise == 3:
    story_practise += "\t" + Pre_sentence_chunk1_practise + "\t" + Pre_sentence_chunk2_practise + "\t" + Pre_sentence_chunk3_practise
    n_chunks_practise = 4

if Number_of_target_sentence_chunks_practise == 1:
    story_practise += "\t" + Target_sentence_chunk1_practise
    n_chunks_practise = n_chunks_practise + 1
elif Number_of_target_sentence_chunks_practise == 2:
    story_practise += "\t" + Target_sentence_chunk1_practise + "\t" + Target_sentence_chunk2_practise
    n_chunks_practise = n_chunks_practise + 2

# group A 1-27 as idioms, and 28 - 54 literal
# reversed for group B
if (group == "A" and Code_practise <= 1027) or (group == 'B' and Code_practise > 1027):
    condition = 'i'
    story_practise += "\t" + KEY_sentence_chunk_IDIOM_practise
    n_chunks_practise = n_chunks_practise + 1
    crit_chunk_practise = n_chunks_practise
elif (group == "B" and Code_practise <= 1027) or (group == 'A' and Code_practise > 1027):
    condition = 'l'
    story_practise += "\t" + KEY_sentence_chunk_LITERAL_practise
    n_chunks_practise = n_chunks_practise + 1
    crit_chunk_practise = n_chunks_practise

if Number_of_concluding_chunks_practise == 1:
    story_practise += "\t" + concluding_chunk1_practise
    n_chunks_practise = n_chunks_practise + 1
elif Number_of_concluding_chunks_practise == 2:
    story_practise += "\t" + concluding_chunk1_practise + "\t" + concluding_chunk2_practise
    n_chunks_practise = n_chunks_practise + 2

chunks_practise = story_practise.split("\t")

thisExp.addData('condition', condition)
thisExp.addData('group', group)

When I run this, the first chunk of the story is displayed, then when the second chunk should be displayed the experiment crashes and I get the following error message:

“if (group == “A” and Code_practise <= 1027) or (group == ‘B’ and Code_practise > 1027):
TypeError: ‘>’ not supported between instances of ‘NoneType’ and ‘int’”

What did you try to make it work?:

To test whether the variable ‘Code_practise’ is being allocated a value at all, I inserted a text object with $Code_practise. The correct value appeared on screen.

Link to the most relevant existing thread you have found:

What specifically went wrong when you tried that?:
if (group == “A” and Code_practise <= 1027) or (group == ‘B’ and Code_practise > 1027):
TypeError: ‘>’ not supported between instances of ‘NoneType’ and ‘int’
################# Experiment ended with exit code 1 [pid:8048] #################

Code_practise is coming up as NoneType (i.e. missing).

To me this implies a blank row in your spreadsheet, or an attempt to access Code_practise in Begin Experiment or before the loop starts. Is the code you have displayed in Begin Experiment?

It seems that, for some reason, the code didn’t like the fact that in some trials some of the columns had no entries. I fixed it in the end by changing the way it was built to include more builder components and simplified code - it’s annoyingly inefficient, but it works!

I quite often put x in a cell instead of blank and then have code like:

if spreadsheetImage == 'x':
     thisImage = 'transparent.png'
else:
    thisImage = spreadsheetImage

Reusing routines and components is good practice.