View Single Post
Old Sep 25th, 2005, 11:38 AM   #1
clanotheduck
Newbie
 
Join Date: Sep 2005
Posts: 6
Rep Power: 0 clanotheduck is on a distinguished road
Question Can a function give a global variable a value?

Is there anyway for this to happen?

At the moment, I am working on a little text adventure. I have also recently discovered the joy of functions, but they have one problem; they can't return a value for a global variable!

The following code is a test for a question system I am making for my text adventure game.

At the moment, I want my function to give a value for "answer".

inventory = [ "cat" , "gun" , "wallet" , "condom" ]

answer = 0


def questions(q,ansone,anstwo,ansoneres,anstwores,ansunknown):
    questionloop = 0
    while questionloop != 3:
        ans = raw_input(q)
        if ans == "inven":
            print inventory
        elif ans == ansone:
            print ansoneres
            questionloop = 3
            answer = 1
        elif ans == anstwo:
            print anstwores
            questionloop = 3
            answer = 2
        else:
            print ansunknown
       

questions("Where is my cat?! :","dead","alive","NOOOOOOOO!","THANK GOD!","WTF?!")

if answer == 1:
    print " answer equals 1, the story will continue with this path."
elif answer == 2:
    print " answer equals 2, the story will continue with this path."
else:
    print "no one is going to ever see this text. HAHAHAHAHA!"

And obviously, I always get the text no one will ever see.

Can anyone help me out here?
clanotheduck is offline   Reply With Quote