<div>The full error message says "There's an error in your program: *** 'return' outside function (final(2).py, line 114)</div>
<div> which is were this return statement is..</div>
<div><br> while introselection < 1 or introselection > 2:<br> print 'That area is unavaible please buy the expansion haha'<br> return introselection <br></div>
<div class="gmail_quote">On Sun, Feb 22, 2009 at 10:51 PM, Tony <span dir="ltr"><<a href="mailto:sternbrightblade@gmail.com">sternbrightblade@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hi,</div>
<div>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 </div>
<div>any suggestions out there.</div>
<div> </div>
<div>#This is a Text based RPG</div>
<div># HP = Character hit points, ZHP = Zombie Hit points, ZBHP = Zombie Boss Hit Points<br></div>
<div>def fakemain(): #This is a place holder for me untill im ready to run the program<br>start()</div>
<div> startselection = start()<br> if startselection == 1:<br> character_creation()<br> else:<br> #end game (need the code to exit program)</div>
<div> </div>
<div> charselection = character_creation()<br> if charselection == 1:<br> name = raw_input ('Please Enter Your Name')<br> HP = dice_roll2()<br> print 'Your HP is ',HP<br> elif charselection == 2:<br>
name = raw_input ('Please Enter Your Name')<br> HP = dice_roll()<br> print 'Your HP is ',HP<br> else:</div>
<div> </div>
<div>intro_area()</div>
<div> introselection = intro_area()<br> if introselection == 1:<br> print 'A Zombie Attacks you'<br> fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)<br> intro_area()<br> else:<br>
back_yard()</div>
<div> backyardselection = back_yard()<br> if backyardselection == 1:<br> fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)<br> else:<br> print 'The Zombie leaps and reaches you before you shut the door.'<br>
print 'YOU HAVE DIED!!!'<br> #reset the game (need the code to reset program)</div>
<div> </div>
<div>Alley()</div>
<div> alleyselection = Alley()<br> if alleyselection == 1:<br> police_station()<br> else: #The object here is for the person to die if they select option 2<br> print 'As you try to get something to munch on 5 zombies attack you'<br>
fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)<br> fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)<br> fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)<br> fight(HP, ZHP, weapon)<br>
death(HP, ZHP, ZBHP)<br> fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)</div>
<div> policeselection = police_station()<br> if policeselection == 1:<br> fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)<br> fight(HP, ZHP, weapon)<br> death(HP, ZHP, ZBHP)<br> else:<br>
print 'The door mysteriously locked itself'<br> police_station()</div>
<div>police_backdoor()</div>
<div> policebackselection = police_backdoor()<br> if policebackselection == 1:<br> forest()<br> else:<br> print 'The Front Door is locked only way out is the backdoor'<br> police_backdoor()</div>
<div><br> forestselection = forest()<br> if forestselection == 1:<br> fight(HP, ZBHP, weapon, True)<br> death(HP, ZHP, ZBHP)<br> end()<br> else:<br> print 'Jonas reaches you before you get back and eats your brains'<br>
#End game</div>
<div> endselection = end()<br> if endselection == 1:<br> #End program or play rick roll'd haha<br> else:<br> #reset program</div>
<div> </div>
<div><br>#This mod is the first area you are in<br>def intro_area():<br> introselection = 0<br> print ' Welcome to Zombie Survival'<br> print ' It is a quite night in Egad, Wisconsin when..You suddenly awake'<br>
print ' to the sounds from outside. You see sparks outside from your window.'<br> print ' The phone line has been cut. You have nothing to help you fend'<br> print ' of attackers. What will you do!!!'<br>
print<br> print '1. Open the Front door?'<br> print '2. Go out the back door and towards the alley?'</div>
<div> while introselection < 1 or introselection > 2<br> print 'That area is unavaible please buy the expansion haha'<br> return introselection<br> <br>#This is the second area of the RPG<br>
def back_yard():<br> backyardselection = 0<br> print ' As you make your way out the back door, a Zombie appears from the'<br> print ' side of the yard. He is slowly making his way to you, and you have'<br>
print ' to kill him to get to the alley. What course of action will you take.'<br> print<br> print '1.Fight the Zombie?'<br> print '2.Run Away?'</div>
<div> while backyardselection < 1 or backyardselection > 2:<br> print 'That is a unavailible course of action.'<br> #fight zombie<br> return backyardselection</div>
<div> </div>
<div>#The Alley No Zombie fight here<br>def Alley():<br> alleyselection = 0<br> print 'After you killed the Zombie you begin to cautiously walk down the alley'<br> print 'looking for something to help you fend off anymore Zombies. When you'<br>
print 'get near the end of the alley you find a baseball bat and a first aid'<br> print 'kit laying on the ground, You instinctifly pick up the bat and first'<br> print 'aid kit, You reach the end of the alley, and you look around for a'<br>
print 'place to hide. Then you remeber about the forest beyond the police'<br> print 'station. What will you do?'<br> print<br> print '1.Run to the police station?'<br> print '2.Run to the grocery store?'</div>
<div> while alleyselection < 1 or alleyselection > 2:<br> print 'Theres a group of zombies over there!!'<br> return alleyselection</div>
<div> </div>
<div>#fight 2 Zombies here<br>def police_station():<br> policeselection = 0<br> print 'You make your way down the street and avoid all the zombies. when you'<br> print 'reach the police station, The lights are flickering on and off. You see'<br>
print 'couple people moving around on the inside. As you open the front door'<br> print 'the two zombies look at you and start heading torwards you. You raise'<br> print 'your bat and prepare to kill them. What will you do first?'<br>
print <br> print '1.Stand your ground?'<br> print '2.Run back outside the door?'</div>
<div> while policeselection < 1 or policeselection > 2:<br> print 'Impossible please try again'<br> return policeselection<br> #fight 2 zombies</div>
<div> </div>
<div>#No Zombies here <br>def police_backdoor():<br> policebackselection = 0<br> print 'You look down at the two zombies you just killed and see a gun.'<br> print 'You lean over and grab the gun and the ammo. Then you start to'<br>
print 'look around and you notice another first aid kit, You walk over'<br> print 'there and patch yourself up. After your done you head towards the'<br> print 'back door. what will you do?'<br>
print<br> print '1.Open the door?'<br> print '2.Go Home?'</div>
<div> while policebackselection < 1 or policebackselection > 2:<br> print 'Not possible'<br> return policebackselection</div>
<div> </div>
<div>#last area, boss is here<br>def forest():<br> forestselection = 0<br> print 'You open the back door and you begin to walk out into the forest.'<br> print 'As your steping through the trees, you look ahead of you and you'<br>
print 'see someone moving slowly towards you. As you focus you see that'<br> print 'its your old army buddy Jonas, You yell at him but he just keeps'<br> print 'moving towards you. You begin to notice that he is also a zombie'<br>
print 'What will you do now?'<br> print<br> print '1.Draw your gun and kill Jonas?'<br> print '2.Go back into the police station?'</div>
<div> while forestselection < 1 or forestselection > 2:<br> print 'That option will be in the expansion lol'<br> return forestselection<br> #Fight Boss here</div>
<div><br>#this is for the Ending<br>def End():<br> endselection = 0<br> print 'You have completed the Zombie survival game.'<br> print<br> print '1. End Game'<br> print '2. Start Over'</div>
<div> while endselection < 1 or endselection > 2:<br> print 'Dont Taze me!!'<br> return endselection</div>
<div> </div>
<div>#this is for the start of the game<br>def start():<br> startselection = 0<br> print ' Zombie Survial 1.0.1'<br> print<br> print '1. Start Game<br> print '2. End Game'<br> #if End game put rick roll'd there<br>
#Survial Mode (only if i can get this finished)<br> while startselection < 1 or startselection > 2:<br> print 'Please enter a selection 1 or 2<br> startselection = input('Press 1 to start the game')<br>
return startselection</div>
<div> </div>
<div>#This module is for the character creation at the beginning game and determines<br>#how much health you have <br>def character_creation():<br> charselection = 0<br> print ' Create your character'<br>
print '1. Male'<br> print '2. Female'<br> print '3. Be a coward and Quit'</div>
<div> while charselection < 1 or charselection > 3:<br> print 'Please enter a selection 1-3'<br> charselection = input ('please inter gender')<br> return charselection<br> <br>
#This module is for the monster named Zombie<br>def Zombie():<br> ZHP = dice_roll2()<br> while ZHP > 0:<br> return ZHP</div>
<div> </div>
<div>#This is for the Boss named Jonas<br>def Zombie_Boss():<br> ZBHP = dice_roll4()<br> while ZBHP > 0:<br> return ZBHP</div>
<div> </div>
<div>#specific for Zombie Boss HP<br>def dice_roll4():<br> seed()<br> dice4 = random.randrange(4, 24, 1)<br> return dice4</div>
<div> </div>
<div>#This Module is for 2d6 sided dice<br>def dice_roll2():<br> seed()<br> dice2 = random.randrange(2, 12, 1)<br> return dice2</div>
<div> </div>
<div>#This Module is for 1d6 sided dice<br>def dice_roll():<br> seed()<br> dice = random.randrange(1, 6, 1)<br> return dice</div>
<div> </div>
<div>#weapons = fist, gun, baseball bat<br># for regular zombie<br>#call fight(HP, ZHP, weapon)<br># for boss zombie<br>#call fight(HP, ZBHP, weapon, True)<br>def fight(HP, ZHP, weapon, boss=False):<br> if weapon == 'fist':<br>
while HP > 0 and ZHP > 0:<br> damage = 2<br> ZHP = ZHP - damage<br> if boss:<br> HP = HP - dice_roll2()<br> else:<br> HP = HP - 2<br>
elif weapon == 'baseball bat':<br> while HP > 0 and ZHP > 0:<br> damage = dice_roll()<br> ZHP = ZHP - damage<br> if boss:<br> HP = HP - dice_roll2()<br>
else:<br> HP = HP - 2<br> else weapon == 'gun':<br> while HP > 0 and ZHP >0:<br> damge = dice_roll2()<br> ZHP = ZHP - damage<br> if boss:<br>
HP = HP - dice_roll2()<br> else:<br> HP = HP - 2</div>
<div> </div>
<div>#This module is used when you die<br>def death(HP, ZHP, ZBHP):<br> if HP == 0:<br> print 'You have Died.'<br> elif ZHP == 0:<br> print 'You have killed the Zombie.'<br> elif ZBHP == 0:<br>
print 'Right before you kill the Zombie, he runs off.'</div></blockquote></div><br>