Placeholder words and text replacement.

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

So I’m working on a text based game. I was using Twine before, more specifically Sugarcube 2. Now there was a Template API that Sugarcube had that I was using for a lot of things (pronouns, adjectives, nouns, etc…).

So how it would work is you would write your text. For example, “You pet the ?pet.” Then you would create a template for “?pet” either in the form of a single item or an array of several. You could also have the template base its output on a variable. For example if “pet = 7”, it would print the eighth item from the array. Alternatively you could also just have it select one at random. So then “?pet” would be replaced with whatever you set the templates output to (dog, cat, giant fire breathing dragon, etc…)

I’ve been looking for something similar or at the very least a way to create a script to do the same thing, but I haven’t been having much luck so far. Searching for Godot, text, replace, and placeholder in Google hasn’t been getting me much in the way of actual answers and the closest I’ve come so far was Format Strings, which while close, doesn’t seem quite right for my purposes.

Any help with this would be greatly appreciated.

Also, apologies if this ends up being a duplicate. i think my previous question got sent to the void or something.

:bust_in_silhouette: Reply From: jgodfrey

I don’t know whether you’ll find something that’s exactly what you’re looking for or not.

There are a number of somewhat-related Godot assets that you might look at. For example, Godot Text Interface Engine might have at least some of what you want.

Video
Github

If you can’t find something already available, building such a system is likely not too much work, depending on the details.

You can use string substitutions and/or regex tools for finding and replacing the templated strings.

I kind of figured there wouldn’t be an exact 1:1 solution for my problem, but it never hurts to ask. I guess I’ll check out the asset and go from there.

Thanks.

Volk | 2022-07-08 18:05