different errors, return outside function and others

Tony sternbrightblade at gmail.com
Mon Feb 23 07:51:39 CET 2009


Hi,
I am trying to write a small program for my final for school, everytime i
run my program it gives me a return outside function error (after i fixed
all the indentation errors it throws at me), i am not very good at
programing with python atm, so any help would be appreiciated. and if im
missing somethign please feel free to throw
any suggestions out there.

#This is a Text based RPG
# HP = Character hit points, ZHP = Zombie Hit points, ZBHP = Zombie Boss Hit
Points
def fakemain(): #This is a place holder for me untill im ready to run the
program
start()
    startselection = start()
    if startselection == 1:
        character_creation()
    else:
        #end game (need the code to exit program)

    charselection = character_creation()
    if charselection == 1:
        name = raw_input ('Please Enter Your Name')
        HP = dice_roll2()
        print 'Your HP is ',HP
    elif charselection == 2:
        name = raw_input ('Please Enter Your Name')
        HP = dice_roll()
        print 'Your HP is ',HP
    else:

intro_area()
    introselection = intro_area()
    if introselection == 1:
        print 'A Zombie Attacks you'
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
        intro_area()
    else:
        back_yard()
    backyardselection = back_yard()
    if backyardselection == 1:
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
    else:
        print 'The Zombie leaps and reaches you before you shut the door.'
        print 'YOU HAVE DIED!!!'
            #reset the game (need the code to reset program)

Alley()
    alleyselection = Alley()
    if alleyselection == 1:
        police_station()
    else:   #The object here is for the person to die if they select option
2
        print 'As you try to get something to munch on 5 zombies attack you'
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
    policeselection = police_station()
    if policeselection == 1:
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
        fight(HP, ZHP, weapon)
        death(HP, ZHP, ZBHP)
    else:
        print 'The door mysteriously locked itself'
        police_station()
police_backdoor()
    policebackselection = police_backdoor()
    if policebackselection == 1:
        forest()
    else:
        print 'The Front Door is locked only way out is the backdoor'
        police_backdoor()

    forestselection = forest()
    if forestselection == 1:
        fight(HP, ZBHP, weapon, True)
        death(HP, ZHP, ZBHP)
        end()
    else:
        print 'Jonas reaches you before you get back and eats your brains'
        #End game
    endselection = end()
    if endselection == 1:
        #End program or play rick roll'd haha
    else:
        #reset program


#This mod is the first area you are in
def intro_area():
    introselection = 0
    print ' Welcome to Zombie Survival'
    print ' It is a quite night in Egad, Wisconsin when..You suddenly awake'
    print ' to the sounds from outside. You see sparks outside from your
window.'
    print ' The phone line has been cut. You have nothing to help you fend'
    print ' of attackers. What will you do!!!'
    print
    print '1. Open the Front door?'
    print '2. Go out the back door and towards the alley?'
    while introselection < 1 or introselection > 2
        print 'That area is unavaible please buy the expansion haha'
    return introselection

#This is the second area of the RPG
def back_yard():
    backyardselection = 0
    print ' As you make your way out the back door, a Zombie appears from
the'
    print ' side of the yard. He is slowly making his way to you, and you
have'
    print ' to kill him to get to the alley. What course of action will you
take.'
    print
    print '1.Fight the Zombie?'
    print '2.Run Away?'
    while backyardselection < 1 or backyardselection > 2:
        print 'That is a unavailible course of action.'
        #fight zombie
    return backyardselection

#The Alley No Zombie fight here
def Alley():
    alleyselection = 0
    print 'After you killed the Zombie you begin to cautiously walk down the
alley'
    print 'looking for something to help you fend off anymore Zombies. When
you'
    print 'get near the end of the alley you find a baseball bat and a first
aid'
    print 'kit laying on the ground, You instinctifly pick up the bat and
first'
    print 'aid kit, You reach the end of the alley, and you look around for
a'
    print 'place to hide. Then you remeber about the forest beyond the
police'
    print 'station. What will you do?'
    print
    print '1.Run to the police station?'
    print '2.Run to the grocery store?'
    while alleyselection < 1 or alleyselection > 2:
        print 'Theres a group of zombies over there!!'
    return alleyselection

#fight 2 Zombies here
def police_station():
    policeselection = 0
    print 'You make your way down the street and avoid all the zombies. when
you'
    print 'reach the police station, The lights are flickering on and off.
You see'
    print 'couple people moving around on the inside. As you open the front
door'
    print 'the two zombies look at you and start heading torwards you. You
raise'
    print 'your bat and prepare to kill them. What will you do first?'
    print
    print '1.Stand your ground?'
    print '2.Run back outside the door?'
    while policeselection < 1 or policeselection > 2:
        print 'Impossible please try again'
    return policeselection
        #fight 2 zombies

#No Zombies here
def police_backdoor():
    policebackselection = 0
    print 'You look down at the two zombies you just killed and see a gun.'
    print 'You lean over and grab the gun and the ammo. Then you start to'
    print 'look around and you notice another first aid kit, You walk over'
    print 'there and patch yourself up. After your done you head towards
the'
    print 'back door. what will you do?'
    print
    print '1.Open the door?'
    print '2.Go Home?'
    while policebackselection < 1 or policebackselection > 2:
        print 'Not possible'
    return policebackselection

#last area, boss is here
def forest():
    forestselection = 0
    print 'You open the back door and you begin to walk out into the
forest.'
    print 'As your steping through the trees, you look ahead of you and you'
    print 'see someone moving slowly towards you. As you focus you see that'
    print 'its your old army buddy Jonas, You yell at him but he just keeps'
    print 'moving towards you. You begin to notice that he is also a zombie'
    print 'What will you do now?'
    print
    print '1.Draw your gun and kill Jonas?'
    print '2.Go back into the police station?'
    while forestselection < 1 or forestselection > 2:
        print 'That option will be in the expansion lol'
    return forestselection
            #Fight Boss here

#this is for the Ending
def End():
    endselection = 0
    print 'You have completed the Zombie survival game.'
    print
    print '1. End Game'
    print '2. Start Over'
    while endselection < 1 or endselection > 2:
        print 'Dont Taze me!!'
    return endselection

#this is for the start of the game
def start():
    startselection = 0
    print '      Zombie Survial 1.0.1'
    print
    print '1. Start Game
    print '2. End Game'
            #if End game put rick roll'd there
            #Survial Mode (only if i can get this finished)
    while startselection < 1 or startselection > 2:
        print 'Please enter a selection 1 or 2
        startselection = input('Press 1 to start the game')
    return startselection

#This module is for the character creation at the beginning game and
determines
#how much health you have
def character_creation():
    charselection = 0
    print '         Create your character'
    print '1. Male'
    print '2. Female'
    print '3. Be a coward and Quit'
    while charselection < 1 or charselection > 3:
        print 'Please enter a selection 1-3'
        charselection = input ('please inter gender')
    return charselection

#This module is for the monster named Zombie
def Zombie():
    ZHP = dice_roll2()
    while ZHP > 0:
    return ZHP

#This is for the Boss named Jonas
def Zombie_Boss():
    ZBHP = dice_roll4()
    while ZBHP > 0:
    return ZBHP

#specific for Zombie Boss HP
def dice_roll4():
    seed()
    dice4 = random.randrange(4, 24, 1)
    return dice4

#This Module is for 2d6 sided dice
def dice_roll2():
    seed()
    dice2 = random.randrange(2, 12, 1)
    return dice2

#This Module is for 1d6 sided dice
def dice_roll():
    seed()
    dice = random.randrange(1, 6, 1)
    return dice

#weapons = fist, gun, baseball bat
# for regular zombie
#call fight(HP, ZHP, weapon)
# for boss zombie
#call fight(HP, ZBHP, weapon, True)
def fight(HP, ZHP, weapon, boss=False):
    if weapon == 'fist':
        while HP > 0 and ZHP > 0:
            damage = 2
            ZHP = ZHP - damage
            if boss:
                HP = HP - dice_roll2()
            else:
                HP = HP - 2
    elif weapon == 'baseball bat':
        while HP > 0 and ZHP > 0:
            damage = dice_roll()
            ZHP = ZHP - damage
            if boss:
                HP = HP - dice_roll2()
            else:
                HP = HP - 2
    else weapon == 'gun':
        while HP > 0 and ZHP >0:
            damge = dice_roll2()
            ZHP = ZHP - damage
            if boss:
                HP = HP - dice_roll2()
            else:
                HP = HP - 2

#This module is used when you die
def death(HP, ZHP, ZBHP):
    if HP == 0:
        print 'You have Died.'
    elif ZHP == 0:
        print 'You have killed the Zombie.'
    elif ZBHP == 0:
        print 'Right before you kill the Zombie, he runs off.'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090222/0244ded7/attachment.html>


More information about the Python-list mailing list