godot-cpp
godot-cpp copied to clipboard
PackedStringArray returning ungrouped characters after loading from a resource
Godot version
v4.2.1.stable.official [b09f793f5]
godot-cpp version
godot-4.2-stable
System information
Godot v4.2.1.stable - Fedora Linux 39 (KDE Plasma) - Wayland - Vulkan (Forward+) - dedicated AMD Radeon RX 7900 XT (RADV NAVI31) () - AMD Ryzen 9 7950X 16-Core Processor (32 Threads)
Issue description
when trying to get a packed string array from a resource, the array returns an array of seprate chars instead of full words so an Array could be made as ["test","godot","git"] but when queried it'll be returned as ["t","e","s","t",",","g","o","d","o","t",",","g","i","t"]
Steps to reproduce
create a resource, give it a PackedStringArray and store the result of String.split() in it, try to query that array during runtime
Minimal reproduction project
also, in the getStringLine() method, if delimitText() is called there, then the array works as intended (most likely because it rewrites the entire array to exactly how String.split() writes it)
also also, StringLine was made as a hacky work around and doesn't seem to actually work
Taking a look at your project, what I think is happening, is String::split()
is getting called with a delimiter of ""
. For example, see this GDScript code:
func _ready():
var s = "test godot git"
print (s.split(""))
It will print:
["t", "e", "s", "t", " ", "g", "o", "d", "o", "t", " ", "g", "i", "t"]
Probably you want it to be called with a delimiter of " "
(a space)? For example, in GDScript:
func _ready():
var s = "test godot git"
print (s.split(" "))
And this one prints:
["test", "godot", "git"]
This could be a matter of running LoremDocument::delimitText()
before the delimiter is set (since it would default to ""
when created)?
ok, so taking that advice into consideration, I actually saw a bug with how I was delimiting the text, I wasn't verifying if the delimiter was actually valid before denoting the text, after doing that it works perfectly now.