0

I have numbered my lists layer1, layer2 ... I want to use a variable (playery) as the number in the lists name when calling it, so if playery was equal to 4, the list addressed would be layer4

layer1 = [".", ".", ".", ".", "."]
layer2 = [".", ".", ".", ".", "."]
layer3 = [".", ".", "■", ".", "."]
layer4 = [".", ".", ".", ".", "."]
layer5 = [".", ".", ".", ".", "."]
playerx = (3)
playery = (4)
(layer(playery - 1))[playerx-1]= (".")

(layer(playery))[playerx-1]= ("■")

This is what I have so far, but it doesn't work

mklement0
  • 382,024
  • 64
  • 607
  • 775

2 Answers2

0

This is what you should do.

layers = [[".", ".", ".", ".", "."],
          [".", ".", ".", ".", "."],
          [".", ".", "■", ".", "."],
          [".", ".", ".", ".", "."],
          [".", ".", ".", ".", "."]]

>> playerx = 3
>> playery = 4
>> layers[playery - 1][playerx - 1]= "."
>> layers[playery][playerx - 1]= "."
Reck
  • 1,388
  • 11
  • 20
0

Create 2D array like this:

layers= [layer1, layer2, layer3, layer4, layer5]

and if you want to get "■" you should type:

layers[2][2]
Henry
  • 1
  • 1