Godot Version
4.4.1.stable
Question
Even if you buy multiple airships, every time you send an airship, it “resets” the airship button instead of making a new airship button after sending a new set of cargo. I’d appreciate feedback on how to fix this.
This video shows how the error happens: https://drive.google.com/file/d/1ye7QXlZm1a0nZP8tYIemnIngeVFgWeB-/view?usp=drive_link
I have the relevant code in the ‘World _Map’ node (which is Autoloaded):
extends Node2D
signal cargo_sent()
var current_city: String = "Los Angeles"
var cargo_income: int
var destination: String
var travel_distance: float
var balance: int = 0
This is the code I had under the “TileMapLayer” node:
func _ready():
calendar.text = str("Week " + str(timer_counter) + ", " + str(year))
camera_2d.global_position = map_to_local(Vector2(78, 165))
balance_label.text = "$ " + str(WorldMap.balance)
populate_cities()
WorldMap.cargo_sent.connect(airship_transit)
if WorldMap.cargo_income != 0:
airship_transit()
func airship_transit():
#Spawns new airship button in World Map
var airship_btn = Button.new()
airship_btn.icon = airship_sprite
airship_btn.flat = true
airship_btn.position = map_to_local(WorldMap.cities[WorldMap.current_city])
add_child(airship_btn)
airship_btn.pressed.connect(self.button_pressed.bind())
#Restarts cargo income variable
WorldMap.cargo_income = 0
#Moves the spawned airship button from the origin to the destination cities
var tween = create_tween()
tween.tween_property(airship_btn, "position", map_to_local(WorldMap.cities[WorldMap.current_city]), WorldMap.travel_distance * travel_time_multiplier)
tween.tween_property(airship_btn, "position", map_to_local(WorldMap.cities[WorldMap.destination]), WorldMap.travel_distance * travel_time_multiplier)
await tween.finished
airship_btn.queue_free()
#Updates airship count at destination city
WorldMap.active_cities[WorldMap.destination] += 1
These are how I have the nodes organized:
This is the code I have in the “loading_cargo” scnee:
func _on_send_cargo_pressed():
WorldMap.balance = WorldMap.balance + WorldMap.cargo_income
WorldMap.cargo_sent.emit()
WorldMap.active_cities[WorldMap.current_city] -= 1
get_tree().change_scene_to_file("res://scenes/World_Map.tscn")
This code is in the “Cargo” node, which is organized below:

