PackedStringArray has a method called to_byte_array
that will return it as a PackedByteArray, but there seems to be no complimentary that turns it back. PackedByteArray has methods that will convert it into float and int arrays, but nothing for string. Nor does PackedStringArray have any method that lets you initialize it from a PackedByteArray. How am I supposed to turn my bytes back into strings?
How to convert a PackerByteArray into a PackedStringArray?
- Edited
Using the constructors, you can convert both PackedStringArray and PackedByteArray to Array, and you can convert Array to both PackedStringArray and PackedByteArray.
https://docs.godotengine.org/en/4.1/classes/class_array.html#constructors
https://docs.godotengine.org/en/4.1/classes/class_packedstringarray.html#constructors
https://docs.godotengine.org/en/4.1/classes/class_packedbytearray.html#constructors
I tested this code in 4.1.1-stable. It doesn't cause any errors, but I don't know if the results make sense.
# Create PackedStringArray.
var s: PackedStringArray = ["a", "b", "c"]
print_debug(s)
# Convert PackedStringArray to PackedByteArray.
var b: PackedByteArray = s.to_byte_array()
print_debug(b)
# Convert PackedByteArray to Array.
var a: Array = Array(b)
print_debug(a)
# Convert Array to PackedStringArray.
var s2: PackedStringArray = PackedStringArray(a)
print_debug(s2)