The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Need help with text-based adventure!
Discuss Need help with text-based adventure! in the Python Programming forum on Dev Shed. Need help with text-based adventure! Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 16th, 2013, 06:52 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
Time spent in forums: 1 h 41 m 45 sec
Reputation 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!
|

January 16th, 2013, 09:05 AM
|
 |
Contributing User
|
|
|
|
|
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!
|

January 16th, 2013, 11:05 AM
|
|
Contributing User
|
|
Join Date: May 2009
Posts: 291
  
Time spent in forums: 3 Days 18 h 33 m 44 sec
Reputation Power: 7
|
|
|
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.
|

January 16th, 2013, 11:25 AM
|
 |
Contributing User
|
|
|
|
|
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.
|

January 16th, 2013, 12:29 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
Time spent in forums: 1 h 41 m 45 sec
Reputation 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']
]
]]
|

January 16th, 2013, 01:46 PM
|
 |
Contributing User
|
|
|
|
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'],
|

January 16th, 2013, 02:54 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
Time spent in forums: 1 h 41 m 45 sec
Reputation 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|