Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 16th, 2013, 06:52 AM
u28MaddoxtCFGS u28MaddoxtCFGS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 u28MaddoxtCFGS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #2  
Old January 16th, 2013, 09:05 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,360 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 55 m 30 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old January 16th, 2013, 11:05 AM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 291 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
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.

Reply With Quote
  #4  
Old January 16th, 2013, 11:25 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,360 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 55 m 30 sec
Reputation Power: 383
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.

Reply With Quote
  #5  
Old January 16th, 2013, 12:29 PM
u28MaddoxtCFGS u28MaddoxtCFGS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 u28MaddoxtCFGS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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']
         ]
         ]]

Reply With Quote
  #6  
Old January 16th, 2013, 01:46 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,360 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 55 m 30 sec
Reputation Power: 383
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'],

Reply With Quote
  #7  
Old January 16th, 2013, 02:54 PM
u28MaddoxtCFGS u28MaddoxtCFGS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 u28MaddoxtCFGS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Need help with text-based adventure!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap