Godot version
4.0.3 stable
System information
Kubuntu 22.04
Issue description
I have a dictionary with string keys, and one of the keys is "" (empty string). To get values from dictionary by the key, the StringName parameter is used. So all works fine unless the key is an empty StringName.
Context: dictionary stores some data about input actions, that are type of StringName (and certain Input and InputEvent methods expects StringName arguments), that's why this type is prefered rather than String. And one of the dictionary elements is kinda nil-element, used to eliminate if _dict.has(key) checks.
Steps to reproduce
- Make *.gd script
- Add a Dictionary variable, e.g.
var _dict:={}
- Add some value with empty key
_dict[&""]=someval or _dict[""]=someval
- Try to get this value like
print(_dict[&""])
Minimal reproduction project
Example declaration:
class_name Something extends Node
var _dict:={&"":"--emptyness--",&"a":"A"}
func get_val_by_strname(key:StringName):
return _dict[key]
func get_val_by_strname_converted(key:StringName):
return _dict[key as String]
func get_val_by_str(key:String):
return _dict[key]
Example usage:
print(Something.get_val_by_str("A")) #Will print "A".
print(Something.get_val_by_strname_converted(&"A")) #Will print "A".
print(Something.get_val_by_strname(&"A")) #Will print "A".
print(Something.get_val_by_str("")) #Will print "--emptyness--".
print(Something.get_val_by_strname_converted(&"")) #Will print "--emptyness--".
print(Something.get_val_by_strname(&"")) #Will throw an error "Invalid get index of type StringName on base Dictionary".
Godot version
4.0.3 stable
System information
Kubuntu 22.04
Issue description
I have a dictionary with string keys, and one of the keys is "" (empty string). To get values from dictionary by the key, the StringName parameter is used. So all works fine unless the key is an empty StringName.
Context: dictionary stores some data about input actions, that are type of StringName (and certain Input and InputEvent methods expects StringName arguments), that's why this type is prefered rather than String. And one of the dictionary elements is kinda nil-element, used to eliminate
if _dict.has(key)checks.Steps to reproduce
var _dict:={}_dict[&""]=somevalor_dict[""]=somevalprint(_dict[&""])Minimal reproduction project
Example declaration:
Example usage: