I have a class Map (simplified):
from Enums import *
import Globals
import Tile
class Map:
tiles = [] #the actual map, it's a 2D list of Tile objects
for x in range(Globals.mapWidth):
for y in range(Globals.mapHeight):
self.tiles[x][y].addItem(Items.Foliage)
And a class Tile:
class Tile:
items=[]
def __init__(self, type):
self.type = type
def addItem(self,i):
self.items.append(i)
My problem is that the items[] array from the class Tile seems to be shared within every instanciation of the class. For example, at the end of the FOR loops, print(len(self.tiles[x][y].items) return 25 for every tile. Why is it so? I should have 25 lists of size 1, but instead printing the list size in the loop increases from 0 to 25. Can someone explan to me what happens here? Thanks a lot for the help :)