i have an autoload called shipSaving, and an array in it called savedCells. I can access the variable in the same script and get a correct result, but when i try to access it in another script with print(shipSaving.savedCells), it just prints an empty array
func _on_block_placing_new_tile():
var usedCells = tilemap.get_used_cells(0)
for i in usedCells:
var usedCellsId = tilemap.get_cell_source_id(0, Vector2i(i.x, i.y))
if savedCells.has(Vector3i(i.x, i.y, usedCellsId)):
pass
else:
savedCells.append(Vector3i(i.x, i.y, usedCellsId))
some of the code is odd because i was trying to find ways to fix it
There could be lots of scenarios, like: you forgot to call this function to add your tiles. Also it could be that you’re pasting not tiles. Could you provide more information? Maybe everything that regulates it and contacts with it
Is it possible you have more than one instance of shipSaving running?
One instance is getting the items added and the other just sits empty.
You can check this out by clicking on remote in the editor while running the game and looking for a second instance of shipSaving (or whatever the script is called)
Is this function you show in the autoload script? func _on_block_placing_new_tile():
maybe there is another savedCells variable in this script? Try ctrl+clicking savedCells here and see where it takes you, paste the location it ends up if you please
I have figured it out. something about the variable being changed in a signal function didn’t let it update for all the other things trying to access it, i’m just moving it to the process function