[Tutor] Help

Ray Jones crawlzone at gmail.com
Thu Sep 6 10:35:37 CEST 2012


On 09/03/2012 07:39 AM, Jack Little wrote:
> > Ok, I am somewhat new to python, and I am making a text-based RPG. I get a
> > weird error with this code:
> >
> >
> > #A Python text-RPG
> > #A Jak Production
> > #APOC
> > global ammo
> > global health
> > global lives
> > global exp
> > global food
> > ammo=55
> > health = 100
> > lives=10
> > exp = 0
> > food = 30
> >
> > def part1():
> >    print "50 Days After The Outbreak:You are standing outside of the Empire
> > State Building."
> >    print "Vines, plants, dirt, and grime cover its once-regal surfaces.
> > Huh."
> >    print "I guess if 80% of the world is dead, more people are concerned
> > about survival than sightseeing.God."
> >    print "Generally,us survivors tend to band together. Mostly  it is for
> > good. Not the bandits."
> >    print "  Bandit:'Hey you! What you got in that bag?"
> >    print "I recognized this Bandit as Sam Cabelo. He was the janitor at my
> > office building. Not the nicest fellow."
> >    answer = raw_input("Type 'show' or 'run away' then hit the 'Enter'
> > button.")
> >    if answer == "SHOW" or answer == "Show" or answer == "show":
> >        print "Ahhh. Nice .45 you got there. And some food.Hand it over.(He
> > says this like a threat, reinforced by that revolver in his hand"
> >        answer2 = raw_input("Type either Hand it over or flee")
> >        if answer2 == "HAND IT OVER" or answer2 == "Hand it over" or answer2
> > == "hand it over":
> >            print "Bandit: Good Job.. Go on now"
> >            ammo=ammo-15
> >      
I'll take a stab at it. You are using attempting to modify a global
variable within a procedure. Procedure variables are separate from
global variables. Global variables must be passed into a procedure using
something on the order of 'part1(ammo)', and then returned back from the
procedure with a 'return <value>'


Ray


More information about the Tutor mailing list