Passing a Variable into a Comment

Hi, I swear I'm not insane. Probably?

I generally know how to manipulate variables/use variables in scripts, and I vaguely know how to get comments from an event page with js, but I don't know how to set a comment programmatically, if such a thing is possible. Would it just be as simple as getting the page comments, getting the comment text, and then changing it to the variable value?

I want to idiot check this before I spend an hour scripting (don't judge, I gotta do it with voice-to-text). If it matters, this is in a Troops' event page (see below):


Screenshot 2025-04-12 100652.png
Comments by themselves don't do anything. Presumably you're using some plugin that parses comments and you want to pass in a variable, whether it will work or not depends on how the plugin is coded. You can try $gameVariables.value(2)

Also the variable has to be declared before the comment or it will just pass in 0 which is the default (if it works)
Ah I wasn't super clear on that. The plugin parses a comment as a string and an integer, and I'd like to change the integer. I do have code that probably tells a better story than the picture, but I'm pretty sure I've messed up my indices somewhere:

JavaScript:
const comments = troop.troop().pages[0].list.find(list => list.code == 108 && list.parameters[0].includes("Fae Sight Display")); // get comments from troops that have "Fae Sight Display"
comments.forEach(comment => {
            const origin = comment.parameters[0].split(":")[1]; // split the string and int
            const change = $gameVariables.value(2); // get the variable value
            origin[1] = change; // pretty sure this is where things start to go wrong, but in theory this should change the original int to the variable's value
            comment.parameters[0] = origin[0].concat(":", change); // merge things back together
        }

I'm pretty rusty, but I hope this makes sense.
Comments by themselves don't do anything. Presumably you're using some plugin that parses comments and you want to pass in a variable, whether it will work or not depends on how the plugin is coded. You can try $gameVariables.value(2)

Also the variable has to be declared before the comment or it will just pass in 0 which is the default (if it works)

Original thread: https://forums.rpgmakerweb.com/threads/passing-a-variable-into-a-comment.176901/