MZ Concatenating script variables into text message?

Hello all of you!

Is there any way I can concatenate variables from my scripts into a message from Show Text command?

Let's say my script is something like this:
JavaScript:
class MainDirector {
    constructor() {
        this.varX = 10;
    }
   
}

const mainDirector = new MainDirector();

And I want to display this varX value into a text message, is there any way I can do it without assigning to a game variable?
Hi!
Yes, there is. But without assigning it to a game variable:
You can either create your own escape code to show this.varX;

Or you can show your text command via script call:
const myVar = mainDirector.varX;
$gameMessage.add('Your variable value is ' + myVar)
OR
$gameMessage.add(`Your variable value is ${myVar}`)

But I think, in these examples, the easiest way is to add it to a game variable anyway...

[EDIT] I'm not so sure about how to show a text message via script call though...
Hi!
Yes, there is. But without assigning it to a game variable:
You can either create your own escape code to show this.varX;

Or you can show your text command via script call:
const myVar = mainDirector.varX;
$gameMessage.add('Your variable value is ' + myVar)
OR
$gameMessage.add(`Your variable value is ${myVar}`)

But I think, in these examples, the easiest way is to add it to a game variable anyway...

[EDIT] I'm not so sure about how to show a text message via script call though...
Nice workaround. I noticed that if adding $gameMessage.add(`Your variable value is ${myVar}`) to an event that has an actor sprite on it, it doesn't face the player when interacted with. Is there any function that displays the message and faces the player altogether?

I just bought RMMZ and I'm kinda sad that it lacks proper documentation, leaving us hunting around for functions to use, or even having to study the source code for it.
Yes, indeed it is not the best documentation...
But, for you to face your character, I think you can use the move route command "face toward the player" or "turn toward the player" something like that.
I don't know how it is in pt-br =/
What is your end goal here? I can't see a reason not to either just use console.log or assign it to a game variable.
What is your end goal here? I can't see a reason not to either just use console.log or assign it to a game variable.
Long story short, my main goal is to have "hunting quests" in my game, just like The Witcher 3, or the Monster Hunter franchise. The idea is to keep these quests in a JSON that's loaded when the game loads up, and present them in a list for the player to pick which one he wants to start. Since there would be different "quest givers", I wanted to display some details of the quest (like the description) on a Message box. This description, for example, would be loaded up from this JSON I mentioned.

I know it would be easier to assign the quest description to an in-game variable, but there could be other parameters I would want to use, and I feel I would have to keep over assigning lots of variables all the time only to use for a simple message, I may forget about its index, or anything like that haha.
Yes, indeed it is not the best documentation...
But, for you to face your character, I think you can use the move route command "face toward the player" or "turn toward the player" something like that.
I don't know how it is in pt-br =/

No problem my friend! This snippet helped me a lot already: $gameMessage.add(`Your variable value is ${myVar}`).

Maybe I'll write a plugin that does that, just wanted to check out if there was anything like that natively 🙂
You can assign anything you want to a variable, including an object. If I'm doing it, I'd create a quest manager object, then assign quest objects to the manager, then assign the quest manager object to a specific global var so you can call it with something like $game_variables.value(55).questID(12).desc() to get the description of quest 12. That way you can add functions to the quest manager to say create a list of available, cleared, or failed quests and all $game_variables are saved so you don't have to worry about effecting the save game code and breaking old saves. I'd also probably create a quest data object in the data manager and use it basically like how the game handles the map data where you load it each time so you can update a live file without having to start a new game.

Original thread: https://forums.rpgmakerweb.com/threads/concatenating-script-variables-into-text-message.126378/