#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Need help with text-based adventure!


    Hello all, I'm working on a text-based adventure game for an IT project, as I have finished my GCSE qualifications and am just waiting for the year to end before moving on to taking A level, and thought that a little project would be a nice way to pass the year. However, I'm relatively new to python, and would like help fixing my code. I'm receiving the following error message:

    Traceback (most recent call last):
    File "C:\Users\Tom\Downloads\AdventureGameV2", line 26, in <module>
    ['You followed the passageway to find a lake, only to be filled of intoxicated water', '0', '1', '0', '0', '0', '0']]
    TypeError: list indices must be integers, not tuple

    The '0', '1', '0', '0', '0', '0' numbers are a flag system, as edge detection, and 1 = blocked
    (#if this is set to 1, then the north passage is blocked
    #if set to 0, the choice to go north is offered
    if map[rowPosition][columnPosition][1] == '0' :
    print('Enter N to go north')

    The block of code in which the error seems to occur is:

    Code:
      [ ['You are now in an increasingly widening cave, you can clearly make out a door to the East and a narrow but accessible passageway to the South.', '0', '0','0','1','0','0'],
             ['You enter through the door, you notice there are stairs leading down to the North, you hear a strange noise to the South, and the sound of running water to the East', '0', '0','0','0','0','0'],
             ['You followed the passageway to find a lake, only to be filled of intoxicated water', '0', '1', '0', '0', '0', '0']]
             ['You walk up the stairs, you notice the intoxicated lake below the ridge you now stand on. You see a ladder to the East, you look up and are stunned by a bright light and sounds of the outside world', '1','1','1','1','0','0']
    Any heads-up on what I'm doing wrong would be appreciated! Also, if you require further sections of code, do not hesitate to ask!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    The only possible error I saw in the code you posted is "intoxicated water". Water can be "intoxicating", unless it is alive. Is water in your game alive? How subtle! Like Ice IX.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    516
    Rep Power
    34
    Extra right bracket "]" and no comma, or the following line should be commented out if you are doing this to test.

    list_indices = some list[number] ## note the brackets

    and do you have a variable assigned to all of this on the line before and not posted. It may very well be on the previous line also.
    Last edited by dwblas; January 16th, 2013 at 11:13 AM.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    I guess I'd need more code. Hoping that dwblas answered your question and you don't reply because this is finished.
    I tested by left-justifying the two lists in your code block, python accepted both as lists. I didn't figure out what "map" is, other than that you probably occluded the built-in definition of map. Hiding the python built-ins is usually poor practice, but I find that I hardly ever use map any more, favoring list comprehensions. Even though they're slow.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Thanks for your help guys, it's really appreciated.
    Here's the main code segment where I suspect the error is.
    This code is just a basic system for me to get the hang of coding in python, so haven't yet bothered proof reading, but thanks for pointing it out!

    Code:
    #This is a text based adventure game
    
    gameRunning = True
    
    #Here is the player's position on the map
    
    rowPosition = 0
    columnPosition = 0
    
    #Here is the game's map
    
    print ("You have several possible inputs. If you wish to view all possible inputs, please type: help - This will print all possible inputs")
    print ()
    print ()
    print ()
    print("You wake up in a strange and barely lit cavern")
    print ()
    print ()
    
    map =[ [ ['The path North and West are blocked off by a rockfall', '1', '0','0','1','0','0'],
             ['You now find yourself at a junction in a narrow passageway. There are rocks strangely shaped as steps to the south, and an ajar wooden door to the East. ', '1', '0','0','0','0','0'],
             ['You enter through the door only to find a passage way to the South, or the door you entered through. The smell of the room starts to make you feel nauseous', '1','1','0','0','0','0']],
             ['You climb up the ladder, congratulations, you have survived!', '1','1','1','1','0','1']
           [ ['You are now in an increasingly widening cave, you can clearly make out a door to the East and a narrow but accessible passageway to the South.', '0', '0','0','1','0','0'],
             ['You enter through the door, you notice there are stairs leading down to the North, you hear a strange noise to the South, and the sound of running water to the East', '0', '0','0','0','0','0'],
             ['You followed the passageway to find a lake, only to be filled of infected water', '0', '1', '0', '0', '0', '0']]
             ['You walk up the stairs, you notice the lake below the ridge you now stand on. You see a ladder to the East, you look up and are stunned by a bright light and sounds of the outside world', '1','1','1','1','0','0']
           [ ['After travelling for a while through the passage way, it becomes to narrow to carry on south. There is a passage to the East, from which a strange noise arises, or the way you came.', '0', '0','1','1','0','0'],
             ['You followed the passage only to discover that there is nothing suspicious that could have made such a noise. There is a passage to the North and the West, you find a trapdoor to the East.', '0', '0','1','0','0','0'],
             ['You enter the room. There is a trapdoor in the middle of the room. The room is pitch black.', '0', '1','1','0','0','0']
             ['There are stairs leading North, there is improved lighting, but also a damp rotting smell. There is also the way you came.','0','1','0','1','0','0'] 
           [ ['You fall down a hole in the ground into a pit of rigged bear traps, you die on impact. ', '1','1','1','1','1','0']
             ['You see a bright light and sounds of the outside world to the West, it is extremely dark to the East', '1','0','1','0','0','0']
             ['There is a ladder leading North, an appealing room to the West and a cave to the East ', '0','0','1','0','0','0']
             ['You enter a curved cave, You could carry on forward, or come back the way you came', '0','1','1','0','0','0']
             ]
             ]]
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    Looks like you're missing a lot of commas.
    Please find a different way to write the structure so that you can see what you've got.
    Code:
    map =[ [ ['long', '1', '0','0','1','0','0'],
             ['long', '1', '0','0','0','0','0'],
             ['long', '1','1','0','0','0','0']],
             ['long', '1','1','1','1','0','1']
           [ ['long', '0', '0','0','1','0','0'],
             ['long', '0', '0','0','0','0','0'],
             ['long', '0', '1', '0', '0', '0', '0']]
             ['long', '1','1','1','1','0','0']
           [ ['long', '0', '0','1','1','0','0'],
             ['long', '0', '0','1','0','0','0'],
             ['long', '0', '1','1','0','0','0']
             ['long','0','1','0','1','0','0'] 
           [ ['long', '1','1','1','1','1','0']
             ['long', '1','0','1','0','0','0']
             ['long', '0','0','1','0','0','0']
             ['long', '0','1','1','0','0','0']
             ]
             ]]
    Load the room descriptions from a file.

    #ROOM83 is a string
    ROOM83 = ('You walk up the stairs, you notice the lake below the ridge you now stand on. You see a ladder to the East, you look up and are stunned by a bright light and sounds of the outside world')
    ...
    Code:
             # use ROOM83
             [ROOM83, '1','1','1','1','0','0'],
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    I managed to get the code working by reducing the grid from 4x4 down to 3x3

    The following lines were commented out:
    Code:
       ['You climb up the ladder, congratulations, you have survived!', '1','1','1','1','0','1']
       ['You walk up the stairs, you notice the lake below the ridge you now stand on. You see a ladder to the East, you look up and are stunned by a bright light and sounds of the outside world', '1','1','1','1','0','0']
       # ['There are stairs leading North, there is improved lighting, but also a damp rotting smell. There is also the way you came.','0','1','0','1','0','0'] 
          # [ ['You fall down a hole in the ground into a pit of rigged bear traps, you die on impact. ', '1','1','1','1','1','0']
          #   ['You see a bright light and sounds of the outside world to the West, it is extremely dark to the East', '1','0','1','0','0','0']
            # ['There is a ladder leading North, an appealing room to the West and a cave to the East ', '0','0','1','0','0','0']
            # ['You enter a curved cave, You could carry on forward, or come back the way you came', '0','1','1','0','0','0']
    Just to note, the indentation on the code above is not how it is in the actual code - refer to my previous post for the correct formatting.

IMN logo majestic logo threadwatch logo seochat tools logo