Godot Version
4.5.stable
Question
I am trying to append an array named “destination_cities” with keys from a different dictionary, but it is not appending for some reason. Code below:
func create_airship_icon(cargo_amount: int, city_origin: String):
var airship = Button.new()
#Spawns new airship button in World Map
airship.icon = load("res://sprites/Airship_icon.png")
airship.flat = true
var origin_vector = Vector2(map_to_local(WorldMap.cities[city_origin][0]))
airship.position = origin_vector
add_child(airship)
#Adds cities within the range of the airship form origion city, while eliminating the origin city
for key in WorldMap.active_cities:
var distance = origin_vector.distance_to(map_to_local(WorldMap.cities[key][0]))
if distance <= 20:
WorldMap.destination_cities.append(key) #<---Keys are not being added
WorldMap.destination_cities.erase(city_origin)
print(WorldMap.destination_cities)
var destination = WorldMap.destination_cities.pick_random() #<--- Can't take value from an empty array
var destination_vector = Vector2(map_to_local(WorldMap.cities[destination][0]))
var final_distance = origin_vector.distance_to(destination_vector)
The follwing code is found in the WorldMap autoload:
var cities = {
"Los Angeles": [Vector2(78, 165), 1000000, 2000000, 1],
"San Fransisco": [Vector2(73, 161), 1000000, 1000000, 1],
"San Diego": [Vector2(80, 166), 1000000, 1000000, 0],
"Chicago": [Vector2(123, 152), 1000000, 1000000, 0],
"Houston": [Vector2(113, 169), 1000000, 1000000, 0],
"San Antonio": [Vector2(108, 170), 1000000, 1000000, 0],
"Dallas": [Vector2(110, 166), 1000000, 1000000, 0],
"New York": [Vector2(142, 156), 1000000, 1000000, 0],
"Seattle": [Vector2(73, 143), 1000000, 500000, 0],
"Vancouver": [Vector2(71, 139), 1000000, 500000, 0],
"Anchorage": [Vector2(31, 113), 1000000, 500000, 0],
"Detroit": [Vector2(131, 151), 1000000, 500000, 0],
"Washington DC": [Vector2(140, 160), 1000000, 500000, 0],
"Mexico City": [Vector2(108, 187), 1000000, 500000, 0],
"Rio de Janeiro": [Vector2(187, 239), 1000000, 500000, 0],
"London": [Vector2(251, 135), 1000000, 500000, 0],
"Paris": [Vector2(254, 142), 1000000, 500000, 0],
"Berlin": [Vector2(270, 134), 1000000, 500000, 0],
"Rome": [Vector2(270, 153), 1000000, 500000, 0],
"Seoul": [Vector2(437, 160), 1000000, 500000, 0],
"Tokyo": [Vector2(456, 163), 1000000, 500000, 0],
"Beijing": [Vector2(423, 156), 1000000, 500000, 0],
"Taipei": [Vector2(430, 177), 1000000, 500000, 0]
}
var active_cities = [
"Los Angeles",
"San Fransisco",
"San Diego"
]
@export var destination_cities: Array