text adventure game "local variable refferenced before assignment"

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2008
Posts: 19
Reputation: IU34 is an unknown quantity at this point 
Solved Threads: 0
IU34 IU34 is offline Offline
Newbie Poster

text adventure game "local variable refferenced before assignment"

 
0
  #1
Apr 5th, 2008
(new code)

so, my new error message is 'local variable 'gold' refferenced before assignment.'

now what?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: text adventure game "local variable refferenced before assignment"

 
0
  #2
Apr 6th, 2008
I am really not a mind reader, so show us some code that gives the error!
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 19
Reputation: IU34 is an unknown quantity at this point 
Solved Threads: 0
IU34 IU34 is offline Offline
Newbie Poster

Re: text adventure game "local variable refferenced before assignment"

 
0
  #3
Apr 6th, 2008
it's in the link...in the link is the whole code, but here is some....

  1. #
  2. if prompt_hou == 'examine table':
  3. print '''There are a lot of car magazines here. You flip through them and find
  4. 5 gold!'''
  5. gold = gold+5
  6. prompt_house()

and whenever run the program and enter that command, it gives me that error and quits...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Re: text adventure game "local variable refferenced before assignment"

 
0
  #4
Apr 6th, 2008
did you define gold?
gold = gold + 5

if 'gold' is not defined before that statement then it doesn't know what to add 5 onto.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: text adventure game "local variable refferenced before assignment"

 
0
  #5
Apr 6th, 2008
Somewhere above your lines shown you have to give gold a starting value, most likely:
gold = 0
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 19
Reputation: IU34 is an unknown quantity at this point 
Solved Threads: 0
IU34 IU34 is offline Offline
Newbie Poster

Re: text adventure game "local variable refferenced before assignment"

 
0
  #6
Apr 6th, 2008
yeah, i did that at the beginning..

  1. #
  2. #better text adventure test
  3. #Made by J. G. S.
  4.  
  5. gold = 0
  6.  
  7. def start():
  8. print '''You slowly open your eyes and find yourself lying on the ground.
  9. You get up slowly, looking around as you do, and here is what you see.
  10. As far as you can tell, you are in the middle of a field with tall grass.
  11. You cannot see that good unless you jump. You see a sign off to the north.'''

but it still gives me that error...
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: text adventure game "local variable refferenced before assignment"

 
0
  #7
Apr 6th, 2008
If the first code you showed is part of a function you have to tell it that gold is a global variable, start your function code with
  1. global gold
Last edited by sneekula; Apr 6th, 2008 at 2:24 pm.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 19
Reputation: IU34 is an unknown quantity at this point 
Solved Threads: 0
IU34 IU34 is offline Offline
Newbie Poster

Re: text adventure game "local variable refferenced before assignment"

 
0
  #8
Apr 6th, 2008
How would I do that? I tried adding global gold right before the gold = 0...but I got the same error. And i've also tried putting global gold like this:
  1. def start(global gold):
  2. print '''You slowly open your eyes and find yourself lying on the ground.
  3. You get up slowly, looking around as you do, and here is what you see.
  4. As far as you can tell, you are in the middle of a field with tall grass.
  5. You cannot see that good unless you jump. You see a sign off to the north.'''

but then it gives me "Invalid syntax"

what do I do?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 19
Reputation: IU34 is an unknown quantity at this point 
Solved Threads: 0
IU34 IU34 is offline Offline
Newbie Poster

Re: text adventure game "local variable refferenced before assignment"

 
0
  #9
Apr 6th, 2008
okay nevermind...I got it.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum


Views: 1073 | Replies: 8
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC