Mar-27-2019, 02:53 AM
By assigning to soldier_achievement inside earn_achievement, Python thinks the variable is local to the function (at the time the function is defined). Therefore, it can't see the assignment to the global soldier_achievement on line 1. But then when it gets to line 15 at run time, the local version hasn't been assigned yet, and gives you the error.
You would need to pass the global variable to the function as a parameter, and get a new value out as a return value. It would probably be better to have a dictionary with all of those global variables as key/value pairs. However, you should learn more about functions before moving forward. I would suggest the function text_adventure tutorials linked to in my signature, below.
You would need to pass the global variable to the function as a parameter, and get a new value out as a return value. It would probably be better to have a dictionary with all of those global variables as key/value pairs. However, you should learn more about functions before moving forward. I would suggest the function text_adventure tutorials linked to in my signature, below.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures