3 Replies - 498 Views - Last Post: 24 March 2013 - 03:56 PM Rate Topic: -----

#1 mrepic99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-March 13

Trying to define global name for text based python game

Posted 24 March 2013 - 08:22 AM

Hello fellow users. I was trying to make a text multiple choice game in python, and a ran into an annoying error. here is the code for my game so far:

def main():
    import os, sys
    import pygame
    from random import randint

    #INTRODUCTION

    print"\n \n \n                      **************************\n                      *MULTIPLE CHOICE SURVIVAL* \n                      **************************\n \n \n"
    print "Welcome to Multiple Choice Survival!\n This is a game in which many different apocalyptic\n events can occur, and every choice\n is important to your survival."
    print "But before we get started, this game needs to know\n a few things about your self.\n Are you a boy, or a girl?"
    gender_choice = raw_input("type here. >>")

    #DEFINING DIFFERENT IN-GAME PATHS

    def choice_1():
        print "Ok, you are male.\n Anyway,"
        name_choice = raw_input("What is your name? >>")
        name = name_choice
        print "Hello", name, ". How old are you?"
        age_choice = raw_input(">>")
        age =age_choice
        "Ok, you are", age, "\nWe are ready to begin. Type anything to start your survival story."
        start_choice = raw_input(">>")
        
    def choice_2():
        print "Ok, you are female.\n Anyway,"
        name_choice = raw_input("What is your name? >>")
        name = name_choice
        print "Hello", name, ". How old are you?"
        age_choice = raw_input(">>")
        age = age_choice
        print "OK, you are", age, "\nWe are ready to begin. Type anything to start your survival story."
        start_choice = raw_input(">>")
        def choice_21():
            #ZOMBIES
            print "You wake up on a wonderful Saturday morning.\n" 
        apocalypse_int = randint(1, 8)
        if apocalypse_int == 1:
            choice_21()
        if apocalypse_int == 2:
            choice_22()
        if apocalypse_int == 3:
            choice_23()
        if apocalypse == 4:
            choice_24()
        if apocalypse_int == 5:
            choice_25()
        if apocalypse_int == 6:
            choice_26()
        if apocalypse_int == 7:
            choice_27()
        if apocalypse_int == 8:
            choice_28()

        #Calling CHOICES 1 AND 2

    if gender_choice == "boy":
        gender = "Male"
        choice_1()
    if gender_choice == "girl":
        gender = "Female"
        choice_2()
  
main() 

The "apocalypse_int" part SHOUlD choose a random integer, which would tell what path the game should take. I keep getting an error saying "Global name "apocalypse isnt defined" I tried changing the name and putting it in
quotes, but to no avail. Please help this is really annoying me!

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to define global name for text based python game

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2013
  • View blog
  • Posts: 3,037
  • Joined: 21-June 11

Re: Trying to define global name for text based python game

Posted 24 March 2013 - 08:30 AM

On which line are you getting that error?
Was This Post Helpful? 1
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5642
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: Trying to define global name for text based python game

Posted 24 March 2013 - 09:07 AM

# good
if apocalypse_int == 3:
	choice_23()
# bad, see difference?
if apocalypse == 4:
	choice_24()



Also, this is wonky, if legal:
def main():
	import os, sys
	import pygame
	from random import randint



Try:
import os, sys
import pygame
from random import randint

def main():



The choice_1 and choice_2 contain a lot of copy paste code. See if you can't remove your repetition.

Hope this helps.
Was This Post Helpful? 2
  • +
  • -

#4 mrepic99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-March 13

Re: Trying to define global name for text based python game

Posted 24 March 2013 - 03:56 PM

View Postsepp2k, on 24 March 2013 - 08:30 AM, said:

On which line are you getting that error?


Im not getting that error anymore. Thanks anyway.

View Postbaavgai, on 24 March 2013 - 09:07 AM, said:

# good
if apocalypse_int == 3:
	choice_23()
# bad, see difference?
if apocalypse == 4:
	choice_24()



Also, this is wonky, if legal:
def main():
	import os, sys
	import pygame
	from random import randint



Try:
import os, sys
import pygame
from random import randint

def main():



The choice_1 and choice_2 contain a lot of copy paste code. See if you can't remove your repetition.

Hope this helps.

Ok, thanks for the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1