Block not accessing information in loop (2)

Hi! I am trying to make a task that runs on pavlovia eventually, that has 3 blocks (male, female, nonsocial) and cycles through a set of 180 questions without repeats across those blocks. However, I ran into a problem when trying to set up feedback using the block type (called rule) in a coding element. Doesn’t appear to access this information. Are we missing something or is there a better way to do this? I attached all of my files except for the physical photos for privacy reasons.
RSBest.psyexp (54.7 KB)
FullQuestionSet.csv (15.3 KB)
men.csv (73 Bytes)
nonsocial.csv (78 Bytes)
women.csv (76 Bytes)
rule.csv (71 Bytes)


The dilemma we’ve run into here is that we have a csv file the indicates the rule/block the subject is in, but when we try to access that variable via a coding component during the task it doesn’t work the way we expect.

If we just print the rule variable, it does print the information from the csv file in the console. However, when we try to use that rule in if then logic in the each frame tab of a coding component or the begin routine tab of a coding component, it doesn’t appear to work. By that, I mean it doesn’t appear to ever meet the conditions of the if then statement. Therefore the variables that are defined in the if then statement are never created.

It could be that trying to do this using the column of the spreadsheet as a variable in our coding component isn’t the best way, but it seems like you’d be able to utilize that variable.

Can you call variables defined in a csv file in those tabs of the coding component? If so, what do you think we are doing wrong ?

The answer to your penultimate question is yes. However, if you’d like me to try to spot your errors, please could you post this code you are using so I can see it on my phone?

We appreciate any phone error spotting! The rule/gender is a column in our csv file. There might be a better way of doing what this is trying to do, but we thought this would work. It’s in the begin routine tab of our feedback routine.

Hi, on your loop ruletest.csv seems to be the condition file. Can publish this as well? The one that here rule.csv doesn’t seem to have the same columns.

We were trying a couple of different ways of implementing this and then decided to go the if else logic route rather than refer to the extra columns here, but this is the ruletest csv

I notice that you have nonsocial in the rule column but Nonsocial in your code.


print('Does ',textbox.text,' equal ' ,Answer,?')
print('Does ',rule, 'equal ',gender,'?')

Interesting! I get:
Does default text equal ALCOHOL ?
Does men equal men ?

So my textbox input is registering as default text? This is a screenshot of that component

I tested this behavior, and it does reset once the routine is finished. Weird.
Try saving the text in the same routine on “End routine” in a code component and use this varibale in the next routine. textbox_answer = textbox.text.
Make sure to place the code component above the textbox component.

The reason seems to be that textbox.reset() is called when the routine ends. I found this when I compiled the experiment and looked at the code.

1 Like

That seems to help, when I add your change to my print statements
print(‘Does ‘,textbox.text,’ equal ’ ,Answer,’?’)
print(‘Does ‘, textbox_answer ,’ equal ’ ,Answer,’?’)
print('Does ',rule, ‘equal ‘,gender,’?’)

I get

Does default text equal ALCOHOL ?
Does Nonsocial equal Nonsocial ?

But when I put in the correct answer it still throws the error saying the expression variable in our if then logic isnt defined
NameError: name ‘expression’ is not defined

Well, that means it still does not enter the conditional statements.

You can add an assertion in your code component to exit the program if the statement is false. It is a great debugging tool.

assert textbox_answer == Answer, f”{textbox_answer} != {Answer}”

Are your strings matching exactly? Same capitalization? No trailing whitespace etc?

1 Like

I’m pretty confident the strings for the rules in the csv match.

For the textbox, its tricky because there’s the "Type here: " words inside it to start. If I remove that and leave it blank, no white space, I get this error:
text = text.replace(’’, codes[‘ITAL_START’])
AttributeError: ‘NoneType’ object has no attribute ‘replace’

If I put the text "Type here: " into our csv file as part of the answer, it runs through multiple questions (ie expression must be getting defined), but it never displays the image

I think you are right there is a mismatch between our textbox response and the info in the csv. I was under the impression it stripped out whatever was in the textbox I guess!

Adding the text in textbox into the answer field of the csv file at least means it is no longer throwing an expression is not defined error! It is now looking for the paths for the image, which seems like a resolution.

Is adding the textbox text to the csv file the way to go, or is there a way to strip it out before evaluating the match?

That seems to be an error with the component.

Nice that you found the error. I would definitely to some string manipulation in Python rather than changing your csv file. Probably easiest way to clean up textbox_answer:

textbox_answer = textbox.text
textbox_answer = textbox_answer.replace(“Type here:“, “”).strip() # strip to make sure of removing whitespace

Also keep in mind that it might be a good idea to convert both the textbox answer and answer to same captilization. Either using lower() or upper() on both.

Chalking this one up to dumb error but at least I learned something new about the text box component, it needs to have something in it and you should strip it out later.

Thanks so much for your help talking through this! Going to see if I can figure out why its not displaying the image next! Will report and share our progress as we go along!

1 Like