Dont add child on the same position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Asacs

I am working on a farming game, but I dont want to add crops to the same position or overwrite it. How can i prevent the overwrite part?

func _input(event):
if event.is_action_pressed("Plant") and self.get_cellv(tile_pos_infront_of_player) == CONSTANTS.SCRATCH_DIRT_ID:
	var crop_path = "res://Crops/Potato.tscn"
	var crop = load(crop_path).instance()
	crop.initialize(crop_data)
	crop.global_position = tile_pos_infront_of_player * 16
	add_child(crop)

If you need more information for code let me know

:bust_in_silhouette: Reply From: wyattb

Maybe I am confused with the question but the obvious would be to set the position by changing tile_pos_infront_of_player to something like this below:

# Calculate a new position you want crop to appear
crop_position = Vector2(500,500)
crop.global_position = crop_position * 16
add_child(crop)