Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC