Error passing a string dictionary key as argument of a function

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

Hello, I’m new to Godot

I have this dictionary in the MapTiles script:

const centerMaterials : Dictionary = {
"Empty": preload("res://Assets/MapTiles/empty/Center.material"),
"Blue": preload("res://Assets/MapTiles/blue/Center.material"),
"Green": preload("res://Assets/MapTiles/green/Center.material")
}

I define this function to change the material of a MeshInstance in another script:

func changeCenter(newCenter : str):
	$Circle.set_surface_material(1, MapTiles.centerMaterials[newCenter])

When in a third script I call this function:

nodeToAdd.changeCenter("Blue")

I get the error: Expected a type for an argument

If I change func changeCenter(newCenter : str): to func changeCenter(newCenter): it works

Why is this happening?

:bust_in_silhouette: Reply From: Lopy

The signature of your function should be changeCenter(newCenter : String):. str is a function the returns a String, but the actual type is String.

If you struggle to find a type, you can use a default value to infer it from : changeCenter(newCenter := ""):.