Python Forum

Full Version: Locate user input in a string.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
New to Python, new to programming, sort of.. I love to play classic CRPG's, however instead of pulling out the graph paper to map out the dungeons as I play I decided to write a program that essentially allows me the joy of manually mapping out a dungeon, but using a digital map instead. I have no idea what I'm doing and I'm learning as go.

I'm supplying a prompt '(0)>' from which I want to collect user input using:

Con_Command = input(Con_Sole)
Am I adding 'Con_sole' '(0)>' to the users input? I think it is, so I am using this line:

Con_Command = Con_Command[5]
To try and find the first letter of the users input which currently is all I need to know, at least for now. However I'm getting an 'string index out of range error' so I must not be looking in the place place, or the input is not a string, because the if statements never run; hence why I added this line. If I try and print 'Con_Command' I get a memory address so, I'm lost.

#Console
Cursor_Position=[0,0]
Con_Sole = '(0)> '
Con_Command = ''

#Dungeon_Entrances

Dungeon_Entrances=['...you feel something crawling across your feet.',
    '...you get the sense of being watched from somewhere in the darkness just ahead.',
    'You hear a odd scream coming from deeper inside the dungeon',
    'What was that sound? The rattling of bones underfoot me thinks.',
    'Have a coin for the ferryman? You\'re going to be crossing the river styx quite often.']

print(" Welcome to the ye old CRPG Dungeon Mapper. If this is your first\n time here you can read the [M]anual"
" (\'crpgdm manual\'). You can\n also start a \'new\' map, \'load\' a previously explored area, or\n sit here and "
"\'enjoy\' the darkness.\n\n")

print (random.choice(Dungeon_Entrances))
print('\n\n')
Con_Command = input(Con_Sole)
Con_Command = Con_Command[5]


if (Con_Command) == 'new':
    if (Con_Command) == 'n':
        print('new dungeon routine runs here')
if (Con_Command) == 'load':
    if (Con_Command) == 'l':
        print('load routine runs here')
if (Con_Command) == 'enjoy':
    if (Con_Command) == 'darkness':
        print('easter egg routine runs here')
    else:
        print('You\'ll have to be more specific. Type 'Manual' for help or \'crpgdm manual\' on the console.')
What is the output if you print Con_Command?
A moment ago I swear it printed out a memory address, now ,however, it prints the user input as intended without the prompt included. So if I type 'new' Con_Command is 'new'. However the results of the 'if' statements never get's printed. So I assume it's never run.
You need to remove line 21 with the [5]. Also note that line 32 is unreachable.