How to ignore warnings treated as errors in GDScript?

Godot Version

4.3.dev3

Question

In my project settings, I have it set up so that untyped delcarations lead to errors because I want to get in the habit of typing my GDScript code.

Now I want to implement a helper function that returns a random value of a dictionary like below. I can’t really use types here, so is there a way do ignore the warnings for this function?

#ignore-warning
static func get_random_dictionary_entry(dict: Dictionary, rng: RandomNumberGenerator):
	var random_key := dict.keys()[_rng.randi() % dict.size()]
	var random_value := dict[random_key]
	
	return random_value

Nevermind, I’ve found it.

@warning_ignore("untyped_declaration")
static func get_random_dictionary_entry(dict: Dictionary, rng: RandomNumberGenerator):
	@warning_ignore("untyped_declaration")
	var random_key = dict.keys()[rng.randi() % dict.size()]
	@warning_ignore("untyped_declaration")
	var random_value = dict[random_key]
	
	return random_value
1 Like

You can type it as Variant

static func get_random_dictionary_entry(dict: Dictionary, rng: RandomNumberGenerator) -> Variant:
	var random_key: Variant = dict.keys()[rng.randi() % dict.size()]
	var random_value: Variant = dict[random_key]
	
	return random_value
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.