Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got an IndexError when I used teleport #7

Open
natkam opened this issue May 18, 2015 · 1 comment
Open

I got an IndexError when I used teleport #7

natkam opened this issue May 18, 2015 · 1 comment
Assignees

Comments

@natkam
Copy link
Member

natkam commented May 18, 2015

I opened the teleport and I got an IndexError: list index out of range. Here's what I got:

Traceback (most recent call last):
File "rogue.py", line 192, in
curses.wrapper(main)
File "C:\Python34\lib\curses__init__.py", line 94, in wrapper
return func(stdscr, _args, *_kwds)
File "rogue.py", line 187, in main
game.run()
File "rogue.py", line 175, in run
action = self.action()
File "rogue.py", line 127, in action
return actions.Move(self.player, self.map.tiles[y+randint(1,20)][x+randint(1,70)])
IndexError: list index out of range

@mrzechonek
Copy link
Contributor

I think it might be related to teleport's location. Note how target tile is calculated: y + randint, x + randint, meaning that:

  • teleport will only transport you east/south
  • if it's too far to the south or east, calculated index might fall outside of the map

try something like this:

random_tile = random.choice(random.choice(self.map.tiles))

and then

return actions.Move(self.player, random_tile)

krzysztofzuraw pushed a commit that referenced this issue Jun 22, 2015
@krzysztofzuraw krzysztofzuraw mentioned this issue Jun 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants