So I'm coding a small game in python using curses, I have a function to find out a tile's data as shown below:
def tileGrabber(position):
global tile_data
global window
for k in tile_data:
if k[0] == position:
return k
return None
I call this later in an object pick-up function to move said data into the players inventory using the following:
def pickUp(what):
global inven_data
global player_position
if what == 'thisItem':
thisItem = tileGrabber(player_position)
inven_data.append(thisItem)
tileEditor(player_position, [1, 2, 3, 4], [' ', 'empty', None, None])
then the tile editor changes the data of that position empty / None. tile editor as follows:
def tileEditor(position, indexs_to_edit, new_values):
global tile_data
global window
tile_to_edit = tileGrabber(position)
location_of_tile = tile_data.index(tile_to_edit)
for k in range(len(indexs_to_edit)):
tile_data[location_of_tile][indexs_to_edit[k]] = new_values[k]
Using the Tile Editor makes the data stored in the players inventory also set to empty / None. How could I change the tile grabber to return a copy of the data instead of the actual data?
I got it to work using the .copy() function on the tile grabber return but was wondering if there was a better way around this.