I have a simple world map that use a tilemap. I have a function that loops through these tiles and finds tiles belonging to different countries, then edits a dictionary with a key for each country containing an array with their tilemap index and another array for the Vector2 positions.
I want to be able to find out what country a user clicks when they click on a tile. I have two variations of the code for this, the way I think is more effecient:
func _input(event):
if event is InputEventMouseButton:
var tile = $TileMap.world_to_map(event.position)
var cell = $TileMap.get_cellv(tile)
print(tile)
print(cell)
var country = ""
for c in countries:
if countries[c][0] == cell:
country = c
break
else:
continue
print(country + " was clicked!")
Then the way I decided to try after that didn't work:
func _input(event):
if event is InputEventMouseButton:
var tile = $TileMap.world_to_map(event.position)
print(tile)
var country = "Error"
for c in countries:
for vec in countries[c][1]:
if tile == vec:
country = c
break
else:
continue
print(country + " was clicked!")
My country list if it is of any use:
var countries = {
"iceland":[0, []],
"norway" : [1, []],
"sweden" : [2, []],
"finland" : [3, []],
"russia" : [4, []],
"kazakhstan" : [5, []],
"estonia" : [6, []],
"latvia" : [7, []],
"lithuania" : [8, []],
"poland" : [9, []],
"belarus" : [10, []],
"ukraine" : [11, []],
"moldova" : [12, []],
"czechia" : [13, []],
"slovakia" : [14, []],
"hungary" : [15, []],
"austria" : [16, []],
"liech" : [17, []],
"swiss" : [18, []],
"monaco" : [19, []],
"france" : [20, []],
"italy" : [21, []],
"slovenia" : [22, []],
"sanmarino" : [23, []],
"malta" : [24, []],
"spain" : [25, []],
"portugal" : [26, []],
"andorra" : [27, []],
"nether" : [28, []],
"lux" : [29, []],
"belgium" : [30, []],
"germany" : [31, []],
"denmark" : [32, []],
"nonplay" : [33, []],
"romania" : [34, []],
"bulgaria" : [35, []],
"serbia" : [36, []],
"croatia" : [37, []],
"bah" : [38, []],
"mont" : [39, []],
"albania" : [40, []],
"greece" : [41, []],
"cyprus" : [42, []],
"turkey" : [43, []],
"syria" : [44, []],
"lebanon" : [45, []],
"iraq" : [46, []],
"georgia" : [47, []],
"armenia" : [48, []],
"azerbaijan" : [49, []],
"algeria" : [50, []],
"tunisia" : [51, []],
"plain" : [52, []],
"uk" : [53, []],
"ireland" : [54, []],
"macedonia" : [55, []],
"kosovo" : [56, []],
}
for some reason it only detects it when I click on the left and it recognizes it as uk. Here's my map if you need it. Past maybe wales it starts saying uk. Everything before that isn't detected.

This is getting too long so i'm going to end it here.