exported Arrays of Strings

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

Trying to do the following (in a resource)

export(Array, String, "Test 1", "Test 2") var test_array : Array

I then populate a new resource with some values for this array. Printing the test array results in an empty array (its not populated).

If i switch test_array to int type, then it works. I’m running godot 3.2. Have anyone had the same problem?

Try initializing the array with a empty value directly:

export(Array, String, "Test 1", "Test 2") var test_array : Array = []

This might work around a bug in Godot.

Calinou | 2020-04-01 08:24

I have the same issue. I’m using Godot 3.4.4. The initialization trick did not work for me.

monsterousoperandi | 2022-03-24 03:55

:bust_in_silhouette: Reply From: monsterousoperandi

Not really a fix but something I did that works.
You use something like

export (String, MULTILINE) var _string_to_array: String = ""

Then, in the editor you enter the strings you want in an array and use a setter and a getter to access them from other nodes. I used a pipe for the delimiter but you can use whatever you like. in this example you enter the string in the editor:
some string message|Some other string data|other string data

func get_string_to_array() -> PoolStringArray:
	return _string_to_array.rsplit("|")


func set_string_to_array(my_array: PoolStringArray) -> void:
	_string_to_array = my_array.join("|")