Corey, please reply on list (use reply-all).  I know it's annoying to have
to remember that.

---------- Forwarded message ----------
From: Corey Richardson <kb1...@aim.com>
Date: Thu, Oct 1, 2009 at 4:15 AM
Subject: Re: [Tutor] UnboundLocalError and Break
To: Luke Paireepinart <rabidpoob...@gmail.com>


 Luke Paireepinart wrote:

You're using a global variable (playHP) in a function, but you haven't told
the function that playHP is supposed to be a global variable. You're going
to want to change your function definition to:

 def monsAttk (damage, attack): #A monsters attack
*    global playHP*
*

On Wed, Sep 30, 2009 at 9:13 PM, bob gailer <bgai...@gmail.com> wrote:
>
> Something is screwy.
> def monsAttk (damage, attack,playHp): # function expects 3 arguments
> monsAttk(4, 15) # passes 2 arguments
>
> That should raise TypeError: monsAttk() takes exactly 3 argument (2 given)
> So something else is awry.

 *
That's because Corey originally e-mailed code that he had already modified
rather than the code that was generating the error.  The pastebin code is
different.

 Corey, I'm not trying to be an ass, but you're making it difficult for us
to help you and thus we're less inclined to.

Yes...As I was running the code a final time to make sure nothing else was
happening until then before I posted it on pastebin, It came up with that,
so i changed it. Sorry for the inconvenience. I also realize that, but I'm
working on it. And I don't see it as ass-ery, I see it as advice : )
So does that global modifier make sure that, in the function, you are using
the variable assigned outside of the function?
Thanks for the help, ~Corey



My reply:
Yep, that's exactly right.  You are generally discouraged from using global
variables in programming languages (you can read about the various reasons
online) but yeah, you have to tell python whether you're using the global
scope or the local scope.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to