[Tutor] Help

Jack Little jacklittlemc at yahoo.com
Mon Sep 3 16:39:58 CEST 2012


> 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
>            food=food-10
>            return answer3
>        if answer2 == "FLEE" or answer2 == "Flee" or answer2 == "flee":
>            print "He shot you"
>            lives=lives-1
>        else:
>            print "TYPE  SOMETHING CORRECTLY"
>            return part1
>
>    elif answer == "run away" or "Run Away" or "RUN AWAY":
>        print "He shot you... hee hee hee"
>        print "When the input comes up again, type a differet answer"
>    else:
>        print "You didn't type Show or run away."
>        part1()
>
> part1()
>
>
> Here is my error, if it helps
>
> Traceback (most recent call last):
>  File "C:\Users\Jack\Desktop\game2.py", line 45, in <module>
>    part1()
>  File "C:\Users\Jack\Desktop\game2.py", line 28, in part1
>    ammo=ammo-15
> UnboundLocalError: local variable 'ammo' referenced before assignment
>
>
> Thanks,
> Jack Little 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120903/7033794c/attachment-0001.html>


More information about the Tutor mailing list