Hi,
I am trying to create a practice trial that will show participants how close they were to their reproduction. But when I click on ‘d’ to skip to the next stimulus the experiment ends and I get : trials.addData(‘Adjusted Length’, currentlinelen)
UnboundLocalError: local variable ‘trials’ referenced before assignment
################ Experiment ended with exit code 1 [pid:22836] #################
Attaching the code component in feedback and reproduction trial.
I also created separate length and width columns in the spreadsheet for the practice trial.
Thank you very much!
It might be because you are using trials.addData instead of thisExp.addData
I fixed that but didn’t work. Do you think the code and where I put them are correct? Thanks!
You can’t have exactly the same error message if you’ve changed trials.addData. Also, your error message looked local but this is in the online category.
Yes, because it is an online study. I get :difference = abs(prac_line_len - currentlinelen)
TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘float’
################# Experiment ended with exit code 1 [pid:5115] #################
this time so when I see the first line and the one in response trial when I click to ‘d’ to see the next stimulus experiment ends. I am not sure if the code component is correct either?
One of these is undefined. I note that you have currentlinelength in feedback and currentlinelen in code. My guess it that they should be the same
But after fixing these issues(defining etc) should this work (after the reproduction I want to show them a feedback screen that will demonstrate how close they were in their reproduction:
(because I am not sure about this part:f’Incorrect. You were off by {difference:.2f} units.')
Begin experiment:
Msg = ’ ’
Begin routine:
Calculate the absolute difference
difference = abs(prac_line_len - currentlinelen)
Set feedback message
if difference == 0:
msg = ‘Correct’
else:
msg = f’Incorrect. You were off by {difference:.2f} units.’
Personally I don’t use f strings and instead might write msg = 'Incorrect. You were off by ' + str(round(difference, 2)) + ' units.'