Hi, I am still new to Godot and am currently trying to make a tower defense game. I have a method` for building and placing towers, that includes an invalid_tiles array, that prevents the player from building on specific tiles, such as where the enemy path is, and it adds newly built towers to the array as well. The problem is how I remove the towers from the array, as I have the "sell tower" feature in a pop-up menu in the tower scene. I can remove the tower with queue_free(), but the spot the tower was on is still in the invalid_tiles array and the player can't build on that spot.
This is the build code:
func _unhandled_input(event):
if event is InputEventMouseMotion and can_place_tower:
$TowerPlacement.clear()
var tile = $TowerPlacement.world_to_map(event.position)
if not tile in invalid_tiles:
$TowerPlacement.set_cell(tile.x, tile.y, 0)
else:
$TowerPlacement.set_cell(tile.x, tile.y, 1)
elif event is InputEventMouseButton and can_place_tower and event.pressed:
var tile = $TowerPlacement.world_to_map(event.position)
if not tile in invalid_tiles:
can_place_tower = false
$TowerPlacement.clear()
if tower_type == 1 and GlobalScript.level_cash > 294:
var tower1_instance = tower1_scene.instance()
tower1_instance.position = tile * Vector2(32, 32)
add_child(tower1_instance)
invalid_tiles.append(tile)
GlobalScript.level_cash -= 295
update_cash()
this is the pop up menu code for the selling method:
func _upgrade_tower(ID):
lock_visible_2 = false
match(ID):
7:
GlobalScript.level_cash += 150
self.queue_free()
get_parent().update_cash()