Add array_to_stringarray function

This commit is contained in:
JeremyStar™ 2024-03-24 15:56:45 +01:00
parent 35cdadf74d
commit 203018db6f
2 changed files with 15 additions and 0 deletions

View file

@ -44,3 +44,7 @@ func _ready() -> void:
logger.info(misc.format_stringarray(array)) logger.info(misc.format_stringarray(array))
logger.info(misc.format_stringarray(array, "[b]", "[/b]")) logger.info(misc.format_stringarray(array, "[b]", "[/b]"))
``` ```
### *Array[String]* <u>array_to_stringarray</u>(*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.

View file

@ -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) 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 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