Use a Variable inside a text variables Default value

Hello!

I am looking to use multiple instances of an Object. Each one will have a different message in the their own ‘Tip’ Text Variable that will explain what that instance of the object does. No issues here.

I would like these messages to hold variables, since some of the values in tip will change depending on the level etc. Since a text variable’s default value already starts inside quotation marks, I need some form of escape. I’ve tried everything I can think of, at this point I am curious if it is possible to escape a default text object to inject a variable.

For now I will just do it all in the event sheet, instead of in the variable.

If you’re visual:

Edit(grammar)

afaik, no easy way to do it… what I did was made a custom extension with “replaceText” function, like this:

let string = eventsFunctionContext.getArgument('string');
let find = eventsFunctionContext.getArgument('find');
let replace = eventsFunctionContext.getArgument('replace');

eventsFunctionContext.returnValue = string.replaceAll(find, replace);

Then I have a text in the variable (long text) which contains e.g. %death_notes% in it, and then I call the function to replace this “placeholder” with actual text:

Screenshot 2024-12-01 at 20.27.10

I have this function in my PuterJS extension, but I’m sure I have it in other extensions too.

2 Likes

That is quite clever, I will give that a try next time. :nerd_face:

1 Like

There’s a regular expression extension that will do this too. Here’s a link to an example that does it for yarn text. It’s the same issue - a string with a placeholder that you swap out with a particular value.

Thanks MrMen very nicely documented!