diff --git a/docs/docs/reference/misc.md b/docs/docs/reference/misc.md index 83bd1a8..1e64184 100644 --- a/docs/docs/reference/misc.md +++ b/docs/docs/reference/misc.md @@ -44,3 +44,7 @@ func _ready() -> void: logger.info(misc.format_stringarray(array)) logger.info(misc.format_stringarray(array, "[b]", "[/b]")) ``` +### *Array[String]* array_to_stringarray(*Array* array) +Converts an array into a string array. + +If an item is found that is not of type `String`, an empty array is returned. diff --git a/src/Misc.gd b/src/Misc.gd index f0ab90a..886b480 100644 --- a/src/Misc.gd +++ b/src/Misc.gd @@ -60,3 +60,14 @@ func format_stringarray(array: Array[String], item_before: String = "", item_aft output = output.replace("If you somehow see this text report this at https://git.staropensource.de/StarOpenSource/CORE/issues, thank you!", separator_final) return output + +func array_to_stringarray(array: Array) -> Array[String]: + var output: Array[String] = [] + + for item in array: + if typeof(item) != TYPE_STRING: + logger.error("Cannot convert Array to Array[String]: Item '" + str(item) + "' is not of type String") + return [] + output.append(item) + + return output