Dear all,
OS: Mac OS 10.15.7
PsychoPy version: v2021.2.3
Standard Standalone? yes
What are you trying to achieve?:
In the Condition 1 of my experiment I want the participant to be presented with a playing card, followed by a brief pause and then with a feedback message. The participant begins with 2250 euro and he loses or wins money throughout the Condition 1. The money that he loses or wins- and the subsequent feedback that he receives- are predefined in a conditions file. I want, based on specific rows in my conditions file, a message to be presented to the participant with the amount of money that he has at every given time. For example, if he begins with 2250 euro and he wins 50 euro in the first presentation of a playing card, I want him to receive the message " You won 50 euro. Your total amount now is 2300 euro" and so forth.
This is my builder (I highlighted the relevant points):
Very briefly in the content of my loop I have chosen “loopType: sequential” and “Selected rows: 7:23”
And the relevant rows in my conditions file, which is connected with the loop, are:
Inside the Code Component, as you can see in the red square, I have written the following code:
Begin Experiment:
beginamountcon1 = 2250
Begin Routine
if money_1 == 'add50_euro1' :
total_amountcon1 = beginamountcon1
total_amountcon1 += 50
msgfeedbcon1 = "The amount of money that you have now is {} euro.".format(total_amountcon1)
When I run the experiment it begins regularly and shows me all the Components until the “end_of_try_efforts_message2” Component, in Condition 1 it stops and the error that I get is:
52.8307 INFO Loaded monitor calibration from ['2021_11_28 10:53']
Generating PsychoPy script...
## Running: /Users/pauline/Desktop/Academic/University Of Cyprus/5 Έτος/Εαρινό Εξάμηνο 2021-2022/Εργαστήριο Αναπτυξιακής Ψυχοπαθολογίας/Πτυχιακή Εργασία/Task in Computer/exp1_subgr1_fille/exp1_subgr1_lastrun.py ##
227.8102 INFO Loaded monitor calibration from ['2021_11_28 10:53']
1.5671 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
2022-02-28 13:25:24.233 python[77437:5182944] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/fv/td94jv0d44jdnknw9qmk77_00000gn/T/org.opensciencetools.psychopy.savedState
Traceback (most recent call last):
File "/Users/pauline/Desktop/Academic/University Of Cyprus/5 \u0388\u03c4\u03bf\u03c2/\u0395\u03b1\u03c1\u03b9\u03bd\u03cc \u0395\u03be\u03ac\u03bc\u03b7\u03bd\u03bf 2021-2022/\u0395\u03c1\u03b3\u03b1\u03c3\u03c4\u03ae\u03c1\u03b9\u03bf \u0391\u03bd\u03b1\u03c0\u03c4\u03c5\u03be\u03b9\u03b1\u03ba\u03ae\u03c2 \u03a8\u03c5\u03c7\u03bf\u03c0\u03b1\u03b8\u03bf\u03bb\u03bf\u03b3\u03af\u03b1\u03c2/\u03a0\u03c4\u03c5\u03c7\u03b9\u03b1\u03ba\u03ae \u0395\u03c1\u03b3\u03b1\u03c3\u03af\u03b1/Task in Computer/exp1_subgr1_fille/exp1_subgr1_lastrun.py", line 891, in <module>
condition1_writtenmessage_feedback_sub1.setText(msgfeedbcon1)
NameError: name 'msgfeedbcon1' is not defined
##### Experiment ended. #####
I have also tried:
if money_1 == 'add50_euro1' :
total_amountcon1 = beginamountcon1 + 50
msgfeedbcon1 = "You win 50 euro.The amount of money that you have now is {} euro.".format(total_amountcon1)
And I have also tried:
if 'add50_euro1' in money_1 :
msgfeedbcon1 = "You won!"
But I tend to get the same Error Message:
Generating PsychoPy script...
## Running: /Users/pauline/Desktop/Academic/University Of Cyprus/5 Έτος/Εαρινό Εξάμηνο 2021-2022/Εργαστήριο Αναπτυξιακής Ψυχοπαθολογίας/Πτυχιακή Εργασία/Task in Computer/exp1_subgr1_fille/exp1_subgr1_lastrun.py ##
1489.4338 INFO Loaded monitor calibration from ['2021_11_28 10:53']
1.3572 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
2022-03-02 09:43:01.457 python[91940:5813431] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/fv/td94jv0d44jdnknw9qmk77_00000gn/T/org.opensciencetools.psychopy.savedState
Traceback (most recent call last):
File "/Users/pauline/Desktop/Academic/University Of Cyprus/5 \u0388\u03c4\u03bf\u03c2/\u0395\u03b1\u03c1\u03b9\u03bd\u03cc \u0395\u03be\u03ac\u03bc\u03b7\u03bd\u03bf 2021-2022/\u0395\u03c1\u03b3\u03b1\u03c3\u03c4\u03ae\u03c1\u03b9\u03bf \u0391\u03bd\u03b1\u03c0\u03c4\u03c5\u03be\u03b9\u03b1\u03ba\u03ae\u03c2 \u03a8\u03c5\u03c7\u03bf\u03c0\u03b1\u03b8\u03bf\u03bb\u03bf\u03b3\u03af\u03b1\u03c2/\u03a0\u03c4\u03c5\u03c7\u03b9\u03b1\u03ba\u03ae \u0395\u03c1\u03b3\u03b1\u03c3\u03af\u03b1/Task in Computer/exp1_subgr1_fille/exp1_subgr1_lastrun.py", line 886, in <module>
condition1_writtenmessage_feedback_sub1.setText(msgfeedbcon1)
NameError: name 'msgfeedbcon1' is not defined
##### Experiment ended. #####
And of course I have added:
$msgfeedbcon1 #set every repeat
in the Text Component after the above Code Component (as you can see in the red square)
What did you try to make it work?:
I have read the relevant recommendations in the book “Building Experiments in PsychoPy” by Peirce and MacAskill, and those in this forum. This seems to match with my case: (NameError: name ___ is not defined - #2 by jon
But:
- I am writing in a Code Component (and I have chose “Set Every Repeat” in my Loop)
- I don’t think it is a typographical error, because I don’t have written this variable anywhere else (rather than the followed Text Component)
- I tried to initialise my variable in the “Begin Experiment” , like msgfeedbcon1 = “” but I get a space rather than the desired message
- I have tried to delete the files " ~/.psychopy2/appData.cfg" and “~/.psychopy2/userPrefs.cfg” in the PsychoPy Coder>Shelf>Shell, but the error that I get is:
PyShell in PsychoPy - type some commands!
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
rm~/.psychopy3/appData.cfg
File "<input>", line 1
rm~/.psychopy3/appData.cfg
^
SyntaxError: invalid syntax
I get the same message with “psychopy2” in the place of “psychopy3”.
- I have reset the preferences of my experiment, as PsychoPy Preferences → App tab → reset preferences and restart and open your code (I am not sure how to restart and open my code) as mentioned in (NameError: name ___ is not defined - #6 by Liner)
The same NameError message was appearing every time, and not only the message was appearing appropriately a couple of days ago, but I have an other code component with the following code that works perfectly:
Begin Experiment
myCount = 0
Begin Routine
myCount = myCount + 1
if myCount > 4:
try_efforts1_loop.finished = True
if feedbackadjusted == 'Positive Reinforcement' :
msg = "You win money"
msgcolor = "green"
elif feedbackadjusted == 'Negative Reinforcement' :
msg = "You lost money"
msgcolor = "red"
Thank you very much for your time,
Kind Regards,
Pauline