Note that there are some explanatory texts on larger screens.

plurals
  1. PONameError: global name 'attributeSelection' is not defined
    primarykey
    data
    text
    <p>Alright, I am pretty much a brand new programmer in high school with about half a years experience(in Python). I am making a basic text game and have run into an error that I have spent hours on but just can't seem to solve. Sorry if I asked any of this in the wrong way, this is my first question here.</p> <p>Here is my code:</p> <pre><code>############################################################################ # APOCALYPSE GAME - TEXT EDITION # # version 0.0.1 # ############################################################################ ### BEGINNING TEXT. ### print('Hello, and welcome to my apocalypse game - text edition!') print() print('This is my first game, and I would like to make a graphical version') print('later in my career.') print() print('But, for now, here is the text edition of it so you can get a taste') print('of what is to come.') print() print('NOTE: PLEASE ENTER ALL TEXT IN ALL CAPS.') print('CHARACTER SETUP:') print() def gender(): ### ALLOWS USER TO PICK A GENDER FOR THERE CHARACTER. womanOrMan = input('Are you a woman or a man(answer WOMAN/MAN)?') if womanOrMan == 'MAN': print('You are a man.') customizationMan() elif womanOrMan == 'WOMAN': print('You are a woman.') customizationWoman() else: print('Invalid answer. Please try again.') gender() def customizationMan(): ### CHARACTER CUSTOMIZATION FOR MEN. ### print('NOTE: IN THIS AREA YOU MAY USE LOWER CAPS. I WILL TELL YOU WHEN TO USE CAPS AGAIN.') hair = input('What hairstyle do you have?') hairColor = input('What is the color of your hair?') eyeColor = input('What is the color of your eyes?') noseSize = input('How big is your nose(inches)?') beard = input('What is the name of your beard(if none say "NONE")?') bodyType = input('What is your body type?') race = input('What is your race?') clothes = input('What are you wearing?') print() print('Here is a summary of you: ') print() print('You have a ' + hair + ' hairstyle, and you the color of it is ' + hairColor + '.') print('Your eyes are the color ' + eyeColor + '.') print('Your nose is ' + noseSize + ' inches long.') if beard == 'NONE': print('You are clean shaven.') else: print('You have a ' + beard + ' beard.') print('You have a ' + bodyType + ' body type.') print('You are of ' + race + ' background.') print('You are wearing ' + clothes + '.') characterConfirmation() def customizationWoman():### CHARACTER CUSTOMIZATION FOR WOMEN.### print('NOTE: IN THIS AREA YOU MAY USE LOWER CAPS. I WILL TELL YOU WHEN TO USE CAPS AGAIN.') hair = input('What hairstyle do you have?') hairColor = input('What is the color of your hair?') eyeColor = input('What is the color of your eyes?') noseSize = input('How big is your nose(inches)?') bodyType = input('What is your body type?') race = input('What is your race?') clothes = input('What are you wearing?') print() print('Here is a summary of you: ') print() print('You have a ' + hair + ' hairstyle, and you the color of it is ' + hairColor + '.') print('Your eyes are the color ' + eyeColor + '.') print('Your nose is ' + noseSize + ' inches long.') print('You have a ' + bodyType + ' body type.') print('You are of ' + race + ' background.') print('You are wearing ' + clothes + '.') characterConfirmation() def characterConfirmation(): ### CONFIRMS USER WANTS HIS CHARACTER TO LOOK LIKE HIS SELECTIONS FOR SURE. ### print('BEGIN TO ANSWER IN ALL CAPS ONCE AGAIN.') print('Are you sure this is what you want your character to look like(if you') print('enter "YES" you will move on. If you enter "NO" the character creation') print('process will restart)?') characterRestart = input('Enter "YES" or "NO" now:') if characterRestart == "YES": attributeSelection() elif characterRestart == "NO": print('Restarting character creation.') gender() else: print('Invalid answer. Please try again.') print() print() characterConfirmation() gender() ##################################################################################################################################### ##################################################################################################################################### # CHARACTER ATRRIBUTES # ##################################################################################################################################### ##################################################################################################################################### def attributeSelection(): print("Ok. Now it is time to set your character attributes and then you can begin the game") print() print("You're character attributes are very important. They can determine whether or not") print("you survive a certain situation.") print("YOU HAVE 25 SKILL POINTS. SPEND THESE ON THE FOUR ATTRIBUTES") print("STRENGTH, VITALITY, STEALTH, AND EXPERIENCE.") print() print() print("Strength makes you able to kill enemies faster, and to do tasks that") print("you normally coulden't.") print() print("Vitality makes you able to survive longer in combat situations.") print() print("Stealth makes you more likely to beable to avoid cobat situations when they are not") print("necessary and sneak up on enemies when they are.") print() print("Experience makes you more likely to be able to survive bad weather conditions,") print(" enhances your ability to preserve food, and helps you survive on your own") print(" in the wild in general.") print() print() print("TIME TO SELECT YOUR ATTRIBUTES:") print() balance = 25 print("Your SP balance is currently 25.") strength = input("How much SP do you want to put into strength?") balanceAfterStrength = balance - strength if balanceAfterStrength == 0: print("Your SP balance is now 0.") attributeConfirmation() elif strength &lt; 0: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif strength &gt; balance: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif balanceAfterStrength &gt; 0 and balanceAfterStrength &lt; 26: print("Ok. You're balance is now at " + balanceAfterStrength + " skill points.") else: print("That is an invalid input. Restarting attribute selection.") attributeSelection() vitality = input("How much SP do you want to put into vitality?(" + balanceAfterStrength + " left!)") balanceAfterVitality = balanceAfterStrength - vitality if balanceAfterVitality == 0: print("You SP balance is now 0.") attributeConfirmation() elif vitality &lt; 0: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif vitality &gt; balanceAfterStrength: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif balanceAfterVitality &gt; 0 and balanceAfterVitality &lt; 26: print("Ok. You're balance is now at " + balanceAfterVitality + " skill points.") else: print("That is an invalid input. Restarting attribute selection.") attributeSelection() stealth = input("How much SP do you want to put into stealth?(" + balanceAfterVitality + " left!)") balanceAfterStealth = balanceAfterVitality - stealth if balanceAfterStealth == 0: print("Your SP balance is now 0.") attributeConfirmation() elif stealth &lt; 0 : print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif stealth &gt; balanceAfterVitality: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif balanceAfterStealth &gt; 0 and balanceAfterStealth &lt; 26: print("Ok. You're balance is now at " + balanceAfterStealth + " skill points.") else: print("That is an invalid input. Restarting attribute selection.") attributeSelection() experience = input("How much SP do you want to put into experience?(" + balanceAfterStealth + " left!") balanceAfterExperience = balanceAfterStealth - experience if balanceAfterExperience == 0: print("Your SP balance is now 0.") attributeConfirmation() elif experience &lt; 0: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif experience &gt; balanceAfterStealth: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif balanceAfterExperience &gt; 0 and balanceAfterStealth &lt; 26: print("Oops! You did not spend all of your skill points. Restarting attribute selection.") print(" remember to spend all of them this time!") attributeSelection() else: print("That is an invalid input. Restarting attribute selection.") attributeSelection() def attributeConfirmation(): print("ATTRIBUTE CONFIRMATION TEST SUCCESS!") </code></pre> <hr> <h2>The problem is, when I run the code in the shell, this is what happens:</h2> <pre><code>Hello, and welcome to my apocalypse game - text edition! This is my first game, and I would like to make a graphical version later in my career. But, for now, here is the text edition of it so you can get a taste of what is to come. NOTE: PLEASE ENTER ALL TEXT IN ALL CAPS. CHARACTER SETUP: Are you a woman or a man(answer WOMAN/MAN)?MAN You are a man. NOTE: IN THIS AREA YOU MAY USE LOWER CAPS. I WILL TELL YOU WHEN TO USE CAPS AGAIN. What hairstyle do you have?UGLY MULLET What is the color of your hair?BROWN What is the color of your eyes?BLUE How big is your nose(inches)?5 What is the name of your beard(if none say "NONE")?NONE What is your body type?ATHLETIC What is your race?WHITE What are you wearing?JEANS AND A TSHIRT Here is a summary of you: You have a UGLY MULLET hairstyle, and you the color of it is BROWN. Your eyes are the color BLUE. Your nose is 5 inches long. You are clean shaven. You have a ATHLETIC body type. You are of WHITE background. You are wearing JEANS AND A TSHIRT. BEGIN TO ANSWER IN ALL CAPS ONCE AGAIN. Are you sure this is what you want your character to look like(if you enter "YES" you will move on. If you enter "NO" the character creation process will restart)? Enter "YES" or "NO" now:YES Traceback (most recent call last): File "C:/Python32/APOCALYPSE GAME LIBRARY/apocalypseGame.py", line 96, in &lt;module&gt; gender() File "C:/Python32/APOCALYPSE GAME LIBRARY/apocalypseGame.py", line 22, in gender customizationMan() File "C:/Python32/APOCALYPSE GAME LIBRARY/apocalypseGame.py", line 54, in customizationMan characterConfirmation() File "C:/Python32/APOCALYPSE GAME LIBRARY/apocalypseGame.py", line 85, in characterConfirmation attributeSelection() NameError: global name 'attributeSelection' is not defined </code></pre> <hr> <p>I have no idea why I am getting this error. I think that it is telling me that I did not define the function attributeSelection, but I obviously did. I have also checked all my spelling... so i am stumped. Does anyone know how I could fix this? Thanks for the help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload