(Solved) Combine strings and arrays

Hi everyone

I am programming an education game where I use several arrays where students can train german verbforms (Verbentrainer | Play on gd.games). I want to combine strings and several arrays in a single text sprite. It is possible to combine a string with an array: For example:

"Text at the beginning" + textArray[5]

But it doesn’t work adding a string at the end of an array. For example:

textArray[5] + "Text at the end"

In programming languages you usually can place strings anywhere between variables, but in GDevelop this seems not to work. Did I do something wrong, or is this a limitation in Gdevelop?

Hi @miwalder

This should work as expected, not sure why it’s not. Try this and see if it works:
VariableString(textArray[5]) + “Text at the end”

1 Like

I believe this way won’t work because GDevelop doesn’t know the type of the array’s children and so treats the plus as a numeric addition. If the string is first, then it knows to treat the plus as a string concatenation.

@insein’s suggestion should fix your issue.

2 Likes

Hi @insein
Thanks so much for your fast reply. This solution worked perfectly, and I learned something more how GDevelop handles Variables.

1 Like

Hi @MrMen
Thanks for your analysis, that was exactly the solution to my problem. I learned the lesson :wink: