0
gameMap = [['.'] * 5 for _ in xrange(5)]   # '.' represents grass.

This should print something along the lines of:

[['.', '.', '.', '.', '.'], 
['.', '.', '.', '.', '.'], 
['.', '.', '.', '.', '.'], 
['.', '.', '.', '.', '.'], 
['.', '.', '.', '.', '.']]

I'm looking to replace a specific index of this array using the tracked user position. If the user position is at (0, 0), i.e. userpos = gamemap[0][0], and I replace that index with a 'P' so the first row looked like [['P', '.', '.', '.', '.'],, how would I go about tracking that index's original value of '.' so that when the player moves from 0,0 I could replace the that tile with its first value, which in this case would be '.'?

0

1 Answer 1

3

Just save the old value in a variable, e.g. player_room_char:

player_room_char = gameMap[i][j]
gameMap[i][j] = 'P'

...

gameMap[i][j] = player_room_char

Presumably there is only one player, so you should only need a single variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.