(Resolved) How to replace words in a list?

Hi, I would like to know how to replace words with other words. Example: I paste a list with Japanese words, when I do it the words will start to be replaced with the ones that match from another list of words. And if any word does not match with any other word, it will be left the same.

My first inclination is to suggest using a structure, and have map word from one language to the second (Japanese word as the child name, English as the child value). That way you just need to check if the child name exists, and it’s value will be the translated word.

I’m going on the assumption that different character sets can be easily used in GDevelop.

Hi, maybe that will work for me, but I don’t know how to do it. Could you give me a visual example or something? I’m sorry, but I’m a newbie at this.

Create a variable, click on the wrench to change collection type to structure, and add children, filling in the names and values accordingly :

Retrieve structure child values with structure_name[child_name]

To access the translated word, get the Japanese word into a variable (in this case I’ve made it a scene variable named _JapanesWord), and retrieve the translated word:

Thank you! I have one last question, I downloaded a plugin to be able to paste the text from the clipboard, and I also added a text object so that the text can be pasted and translated, but is it possible to use the variables to detect the words in the text object and replace them? Or is it not possible?

You’ll need to use string manipulation here. And doing that using GDevelop events can be a bit tedious.

You’d be much better off using the Javascript code event in GDevelop, splitting the text and passing the results back to GDevelop. It may sound a bit daunting, but in practice it’s far simpler that using normal GDevelop events.

I’m at work at the minute, but if no one else responds, I can help you create the script to achieve what you’re after.

Here’s an example of Javascript code events in action, to give you a taste.

Thank you very much for the help!

Here’s the JavaScript code that’ll take a text and split it into words (it assumes a space marks the word boundaries).

It assumes the text is in a scene string variable named OriginalText, and outputs the split text into an an existing scene array variable named WordArray. It uses space to identify breaks between words.

It won’t remove punctuation or other characters.

No need for JavaScript, the array tools extension has an action for that :wink:

1 Like

Is good to. know but there is some tutorial or documentation of this how to use the array tools extension? I just ask because if not I plan to make some tutorials on this, because this is regular asked question

Sweet, I wasn’t aware of the extension.

I had just added a little more functionality to the javascript solution to remove non-alphabetic characters. Here it is for anyone interested :