(new code)

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

now what?

Recommended Answers

All 8 Replies

I am really not a mind reader, so show us some code that gives the error!

it's in the link...in the link is the whole code, but here is some....

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

and whenever run the program and enter that command, it gives me that error and quits...

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.

Somewhere above your lines shown you have to give gold a starting value, most likely:
gold = 0

yeah, i did that at the beginning..

#
#better text adventure test
#Made by J. G. S.

gold = 0

def start():
   print '''You slowly open your eyes and find yourself lying on the ground.
You get up slowly, looking around as you do, and here is what you see.
As far as you can tell, you are in the middle of a field with tall grass.
You cannot see that good unless you jump. You see a sign off to the north.'''

but it still gives me that error...

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

global gold

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:

def start(global gold):
    print '''You slowly open your eyes and find yourself lying on the ground.
You get up slowly, looking around as you do, and here is what you see.
As far as you can tell, you are in the middle of a field with tall grass.
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?

okay nevermind...I got it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.