When I execute the program (just to test my progress), it returns an infinite loop
(i think of main() or enter(). I am posting the entire source code here, maybe somebody could help me better organize it. In hte future, I would like to add a save feature. This is not going to be what it seems like at first, for more on what i am trying to do, just ask.

# program and theme developed by Matthew Ruane
# for ThemApples Development Uninc.
# this is the main file, the first one to load.
#file name=textual.py
 
 
 
 
 
 
 
 
 
 
def gender_prompt():
    gender_prompt == lower.raw_input("Are you Male, Female, or Both?")
    if gender_prompt == 'm'or'male':
        print "You have been registered as a Male. Now for step two!"
        pick_name_male()
        import male
    elif gender_prompt == 'f' or 'female':
        print "You have been registered as a Female. Now for step two."
        pick_name_female()
    elif gender_prompt == 'b'or 'both':
        print "You have been registered as a Hermaphrodite, Both male and female."
        pick_name_both()
    else:
        print ""
        print ""
        print ""
        print ""
        print "You must enter your gender to proceed. Either type Male, Female, or Both."
        print ""
        print ""
        gender_prompt()
                                
 
 
 
 
def create_gender():
    print ""
    print ""
    print ""
    print ""
    print ""
    print ""
    print "Welcome to the Profile Creator registration process."
    print "I will take you through three easy steps to get into"
    print "the Textual Encounters world."
    print ""
    print ""
    print "First, you will need to pick your gender."
    print "You have three choices: Male, Female, or Both."
    print "Remember, to choose, you can either type the whole word..."
    print "Or just the capital letter. This goes for all of your adventures"
    print "in Textual Encounters."
    print ""
    print ""
    print ""
    print ""
    print ""
    gender_prompt()
def enter():
    enter == lower.raw_input("Type ENTER to go to profile creation.")
    if enter != 'enter':
        print "Please type ENTER to begin"
    else:
        print ""
        print ""
        print ""
        print "Now loading Profile Creator..."
        print ""
        print ""
        print ""
        print ""
        create_gender()
def main():
    print "Welcome to 'Textual Encounters'."
    print ""
    print ""
    print "Programmed by the one and only, Matthew Ruane."
    print ""
    print ""
    print ""
    print ""
    print ""
    print "Before we begin, pick your gender. When choosing options, and throught"
    print "your Textual Experience, capital words are buzz words. Type in the whole "
    print "buzz word, in all lower case letters. If only a few letters are capitalized,"
    print "only type in those. But remember, no caps!"
    print ""
    print ""
    print ""
    main()
    enter()

This is the second file:

#file name = male.py
 

def list_prompt():
    prompt == lower.raw_input("Please select the number of the name you want.")
    if prompt == '1':
        print ""
        print ""
        print ""
        import arius
    elif prompt == '2':
        print ""
        print ""
        print ""
        import doofus
    elif prompt == '3':
        print ""
        print ""
        print ""
        import bob
    else:
        print "That is not a valid choice. Please, pick 1, 2, or 3."
        list_prompt()

def list():
    print ""
    print ""
    print ""
    print " 1: Arius"
    print " 2: Doofus"
    print " 3: Bob"
    list_prompt()
    
 

def pick_name_male():
    print "You have chosen to register as a male."
    print ""
    print ""
    print ""
    print ""
    print ""
    print ""
    print ""
    print ""
    print "You must now choose your name."
    print "Sorry, but you will have to pick your name from a prechosen list."
    print "Someday soon, Textual Encounters will have user defined names. But not now."
    print ""
    print ""
    print "Here is how it works. You type the number of the name you want. More names"
    print "will be coming soon."
    print ""
    print ""
    list()

and the third file:

#file name = arius.py
 

def training2():
    print ""
    print ""
    print "Good job, you sure are getting the hang of things."
    print "Let me tell you about this cell PHONE."
    print ""
    print ""
    print "It is yours, a gift from me. But, first, you must learn how to use it."
    print "To use your cell PHONE, you must type 'USE PHONE'."
    print "The phones menu is self explanitory, but I will still help you out."
    print ""
    print ""
    print "Try it now. USE your PHONE."
    print ""
    print "Then, use it's call feature to go to LUX."
    import promptmain
 
 
 
def training1():
    print "You are in room name START."
    print ""
    print "Good job. If you can handle that then you can handle things around here."
    print "Once in a while you may come across a word that is in all caps."
    print "These words, we call Objects. In Textual Encounters, by typing "
    print "the capitalized word, you can see it's description."
    print "Try it on this cell PHONE."
    import promptmain

def welcome_arius():
    print ""
    print ""
    print ""
    print ""
    print ""
    print ""
    print ""
    print ""
    print "Welcome to Textual Encounters, Arius. I am your tour guide, KEERA. I will be helping "
    print "you find your way around in the lands of Textual Encounters."
    print "But, first, there are a few things you should know about first."
    print ""
    print ""
    print "To advance the screen, type NEXT."
    print "Try that now."
    import promptmain

This is the main prompt code, the main user input.

#file name = promptmain.py
 
 
 

def room_start_desc():
    print ""
    print ""
    print "You are in the START room. There is one person with you."
    print "Her name is KEERA, and she is your guide."
    print "The Objects of interest here are..."
    print "SIGN, KEERA."
    print ""
    print ""
    print "KEERA tells you, 'FOLLOW me, I have something else to show you."
    prompt_main()
 
 
 

def phone_desc():
    print ""
    print ""
    print "This is a Luztee cell phone."
    print "It has a camera, wireless internet, "
    print "a bunch of games, a teleporter, and much more."
    print "You can even add on to it."
    print "The value of this cell phone is about 500 Favors."
    print ""
    print ""
    print "Now, you can type LOOK plus the room name"
    print "to show the room description of"
    print "where you are. Try LOOK START"
    prompt_main()
 
 
def prompt_main():
    print ""
    print ""
    prompt == lower.raw_input():
        if prompt = 'more'or 'm':
            training1()
        elif prompt = 'phone':
            phone_desc()
        elif prompt = 'LOOK START':
            room_start_desc()
        elif prompt = 'follow':
            print ""
            print "FOLLOW who?"
            prompt_main()
        elif prompt = 'follow keera':
            import arius
            training2()
        elif prompt = 'use':
            print "Use what?"
            prompt_main()
        elif prompt = 'use phone':
            import phonemenu
        elif prompt = 'call lux':
            import lux
        elif prompt = 'call job':
            import job
        elif prompt = 'lux':
            print "LUX is the social center of Textual Encounters new arrivals."
            print ""
            prompt_main()
        elif prompt = 'password' or 'save':
            getpassword()

here is the code for file lux.

#file name = lux.py
 

def room_start_desc():
    print ""
    print ""
    print "You are in the START room. There is one person with you."
    print "Her name is KEERA, and she is your guide."
    print "The Objects of interest here are..."
    print "SIGN, KEERA."
    print ""
    print ""
    print "KEERA tells you, 'FOLLOW me, I have something else to show you."
    prompt_main()
 
 
 

def phone_desc():
    print ""
    print ""
    print "This is a Luztee cell phone."
    print "It has a camera, wireless internet, "
    print "a bunch of games, a teleporter, and much more."
    print "You can even add on to it."
    print "The value of this cell phone is about 500 Favors."
    print ""
    print ""
    print "Now, you can type LOOK plus the room name"
    print "to show the room description of"
    print "where you are. Try LOOK START"
    prompt_main()
 
 
def prompt_main():
    print ""
    print ""
    prompt == lower.raw_input():
        if prompt = 'more'or 'm':
            training1()
        elif prompt = 'phone':
            phone_desc()
        elif prompt = 'LOOK START':
            room_start_desc()
        elif prompt = 'follow':
            print ""
            print "FOLLOW who?"
            prompt_main()
        elif prompt = 'follow keera':
            import arius
            training2()
        elif prompt = 'use':
            print "Use what?"
            prompt_main()
        elif prompt = 'use phone':
            import phonemenu
        elif prompt = 'call lux':
            import lux
        elif prompt = 'call job':
            import job
        elif prompt = 'lux':
            print "LUX is the social center of Textual Encounters new arrivals."
            print ""
            prompt_main()
        elif prompt = 'password' or 'save':
            getpassword()

This is the code for phonemenu.py

def help():
    print ""
    print ""
    print "These are the most common and basic controls. You will learn more along the way."
    print "LOOK + object = look at the object. Ex: LOOK SIGN."
    print "USE + object = use an object. Ex: USE PHONE."
    print ""
    print "Type EXIT to leave PHONE MENU."
    phone_menu_menu()
 
 
def camera():
    print ""
    print "You are not yet able to take pics."
    print ""
    print "Type EXIT to leave PHONE MENU."
    phone_menu_menu()
def games():
    print ""
    print "Games are not yet available. Sorry. They are being worked on."
    print "Type EXIT to leave PHONE MENU."
    phone_menu_menu()
 
 
 
 
 
def call():
    print ""
    print ""
    print "The CALL feature allows you to teleport to another place instantly."
    print "For now, you can only CALL two places."
    print "These places are:"
    print ""
    print "1. The Village of LUX."
    print "2. The JOB market of Laborant."
    print ""
    print "To use this feature, type CALL plus place name."
    print "Type EXIT to leave PHONE MENU."
    phone_menu_prompt()
 
 
 
 
def phone_menu_prompt():
    print ""
    print ""
    menu == lower.raw_input("Please make your selection."):
        if menu = '1' or 'call':
            call()
        elif menu = '2' or 'camera':
            camera()
        elif menu = '3' or 'games':
            games()
        elif menu = '4' or 'help':
            help()
        elif menu = '5' or 'exit':
            print ""
            import promptmain
        else:
            phone_menu_prompt()

def phone_menu_menu():
    print ""
    print ""
    print "You are in MAIN MENU"
    print ""
    print "1. CALL (teleports you to a place.)"
    print "2. CAMERA (takes pictures, duh!)"
    print "3. GAMES (coming soon.)"
    print "4. HELP (in game help)"
    print "5. EXIT (go back to Textual Encounters.)
    phone_menu_prompt()

def phone_menu_desc():
    print "You are in PHONE"
    print ""
    print "Welcome to your Luztee CellPhone."
    print ""
    print "Navigate the menu's by choosing the number of the item that you want."
    print ""
    print ""
    phone_menu_menu()
def phone_menu():
    phone_menu_desc()
    phone_menu_menu()
    phone_menu_prompt()

this is the code for jobinfo.py

def job_pick_prompt():
    prompt = lower.raw_input("What do you do?"):
        if prompt == 'choose job slave':
            import ariusslave
        elif prompt == 'job menu':
            import lux
            jobs_prompt()
 
 
 
 

def slave_job_info():
    print ""
    print ""
    print """You are in SLAVE INFO.
    A slave's job is to do the bidding of their master. This includes chores, which must be
    completed in a specific way, doing intimate duties, and often times engaging in multi-
    themed quests.

    A slaves pay is often not the best, usually around 5 Favors (5fav) per completed task.
    The plus slide to entering slavery is that slaves are expensive, and all the Favors go
    to you. In Textual Encounters, a slave costs 1,000fav.
    To chose this profession, use CHOOSE JOB SLAVE. To return to the job menu, use JOB MENU.
    """
    job_pick_prompt()

I hope this isn't to much. I need to better organize it, but first, can't seem to figure where i am going wrong.

Recommended Answers

All 7 Replies

main() in the first program block calls itself, so yes it is an infinite loop. I think what you want is

if __name__ == "__main__":
     main()

This calls main() once and then exits when main() is finished - assuming you also removed main() from def main()

Also, you can do this and avoid the extra print statements

print "Welcome to 'Textual Encounters'.\n\n"
print "Programmed by the one and only, Matthew Ruane.\n\n\n\n\n"

P.S. you have way too much untested code. Your if statements will not work. Code one function or 20 lines, whichever is less, and then test it. Rinse and repeat.

Thanks woooee. Thant helps.

<quote>maybe somebody could help me better organize it.</quote>

A couple of suggestions for tightening up your code:

(1) importing code need only be done once. Thus, your main file should import phenomenu, lux, arius, male, etc. at the top, and then call functions out of those files as needed.

(2) When you call a function imported from another module, the name of that function is now

module.funcname.

Thus, because "pick_name_male" is found in the module "male", when main calls it, it must call

male.pick_name_male()

Jeff

IMHO a dictionary works better for menus. prompt_main() could be written as

def prompt_main():
    prompt_dic={'more':'training1()', 'm':'training1()',
                'phone':'phone_desc()',
                'LOOK START':'room_start_desc()',
                'follow':'print_follow()'}          ## etc
    prompt = raw_input().lower()
    if prompt in prompt_dic:
       eval(prompt_dic[prompt])
    else:
       prompt_main()
    print "\n"

Some people don't like using eval() because it will execute any code given to it, but the sky won't fall when using it with the code you have written.

Is there a way to make a value a global, after the user has modified it? It would be nice for me to have these two major functionalities, User Defined Charector Names, and the ability
to save the progress when they are done. I guess the two go hand in hand. I have thought about having python take a snapshot, but, intelligence actually possessed my body for a brief moment, and realized I wasn't trying to get a boring photo of text.

Yes you can. There is more than one way. The accepted method is to use a class so try it out. Then you can use self.user_defined_character_names_list (or something shorter) anywhere in the class. The 'self' just means that it is a member (belongs to) the class. This looks like a good learning project as it covers a lot. Next, you might want to try storing data in a database. This should get you there http://www.python.org/doc/current/tut/node11.html but as an example, you basically just have to do something like

import arius         ## assume this function is in a separate file

class SomeClass:
   def __init__(self, variables, passed):  
      self.user_defined_character_names_list = []
      self.prompt_main()      ## calls the main prompt

   def prompt_main(self):
      if training2:                 ## or whatever
        arius.training2()         ## assume this is still in separate file
      self.user_defined_character_names_list.append(something)

if __name__ == "__main__":
   SC=SomeClass( any, variables )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.