Is it possible to make labels variable?

Hey guys,

Im currently trying to figure out if its possible to make labels variable to basically get something the effect of this:
Code:
◆Control Variables:#0110 TEst = Random 1..3
◆Jump to Label:$gameVariables.value(110)
◆Label:1
◆Text:None, Window, Bottom
:    :1
◆Exit Event Processing
◆Label:2
◆Text:None, Window, Bottom
:    :2
◆Exit Event Processing
◆Label:3
◆Text:None, Window, Bottom
:    :3
◆Exit Event Processing
Obviously the method above didnt work, or i wouldnt be posting here - and I cant really think of any other way to make a label variable. If you guys know if its possible, and if so, how to pull it off; id greatly appreciate it!
I don't think that's possible. You would have to use Conditional Branches for that.
I don't think that's possible. You would have to use Conditional Branches for that.
ah thats a shame
I haven't tested it, but just a suggestion. It might work if you store a string in the variable instead of a number. Eg. Store '1' instead of 1?

*EDIT* scratch that I was being a moron. See this post: https://forums.rpgmakerweb.com/index.php?threads/how-use-label-in-script-call.64996/

Try script call this.command119(toString($gameVariables.value(110)))
You'd need a plugin to allow that. I wrote a script in Ace to do it ... will see if I can port it to MV.

Bump if I don't post it in the next 24 hours.

edit: don't need to now.
I haven't tested it, but just a suggestion. It might work if you store a string in the variable instead of a nu
I haven't tested it, but just a suggestion. It might work if you store a string in the variable instead of a number. Eg. Store '1' instead of 1?

*EDIT* scratch that I was being a moron. See this post: https://forums.rpgmakerweb.com/index.php?threads/how-use-label-in-script-call.64996/

Try script call this.command119(toString($gameVariables.value(110)))
I think you meant that i should use it like this:
Code:
◆Control Variables:#0110 TEst = 2
◆Script:this.command119(toString($gameVariables.value(110)))
◆Label:1
◆Text:None, Window, Bottom
:    :1
◆Exit Event Processing
◆Label:2
◆Text:None, Window, Bottom
:    :2
◆Exit Event Processing
◆Label:3
◆Text:None, Window, Bottom
:    :3
◆Exit Event Processing
And sadly that didnt work out. In the scriptcall I also tried to replace ''$gameVariables.value(110)'' with 2. Also I tried using "2" instead of 2, and nothing worked. Did I use it right?
did you get an error message? What did it say? What's in the console when you hit F8?
did you get an error message? What did it say? What's in the console when you hit F8?
No error, and nothing changed in the console log as far as i know.
I tried console.log in game interpreter.
Code:
Game_Interpreter.prototype.command119 = function() {
    var labelName = this._params[0]; console.log(labelName); console.log(typeof labelName);
    for (var i = 0; i < this._list.length; i++) {
        var command = this._list[i];
        if (command.code === 118 && command.parameters[0] === labelName) {
            this.jumpTo(i);
            return;
        }
    }
    return true;
};

This is the result. Interesting...
Code:
this.command119(toString($gameVariables.value(6)))
string

So I added this into game interpreter, rpg_objects.js
Code:
// Jump to Label 2
Game_Interpreter.prototype.jumpToLabel = function(label) {
    for (var i = 0; i < this._list.length; i++) {
        var command = this._list[i];
        if (command.code === 118 && command.parameters[0] === label) {
            this.jumpTo(i);
            return;
        }
    }
    return true;
};

Did the script call
Code:
this.jumpToLabel($gameVariables.value(6).toString());

and it jumped to the label! So you can also add a new command to game interpreter, or download the plugin I attached and use this.jumpToLabel

As a side, I'm quite interested to know why the original function uses this._params[0]. What's going on when the game calls the function?
I tried console.log in game interpreter.
Code:
Game_Interpreter.prototype.command119 = function() {
    var labelName = this._params[0]; console.log(labelName); console.log(typeof labelName);
    for (var i = 0; i < this._list.length; i++) {
        var command = this._list[i];
        if (command.code === 118 && command.parameters[0] === labelName) {
            this.jumpTo(i);
            return;
        }
    }
    return true;
};

This is the result. Interesting...
Code:
this.command119(toString($gameVariables.value(6)))
string

So I added this into game interpreter, rpg_objects.js
Code:
// Jump to Label 2
Game_Interpreter.prototype.jumpToLabel = function(label) {
    for (var i = 0; i < this._list.length; i++) {
        var command = this._list[i];
        if (command.code === 118 && command.parameters[0] === label) {
            this.jumpTo(i);
            return;
        }
    }
    return true;
};

Did the script call
Code:
this.jumpToLabel($gameVariables.value(6).toString());

and it jumped to the label! So you can also add a new command to game interpreter, or download the plugin I attached and use this.jumpToLabel

As a side, I'm quite interested to know why the original function uses this._params[0]
I put your code in a plugin instead, since i try to not make changes to the main code - and it WORKS indeed! Thanks so much dude!
Since I'm at it and I might need this sometime, if you add this to a plugin you can now use

Plugin command: jumpToLabel 101
Script call: this.jumpToLabel(101)

Code:
(function() {

var _Game_Interpreter_pluginCommand =
        Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if (command === 'jumpToLabel') {
        var label = [$gameVariables.value(args).toString()];
        jumpToLabel.apply(this, label);
    }
};

Game_Interpreter.prototype.jumpToLabel = function(variable) {
    var label = [$gameVariables.value(variable).toString()];
    jumpToLabel.apply(this, label);
};

function jumpToLabel(label) {
    for (var i = 0; i < this._list.length; i++) {
        var command = this._list[i];
        if (command.code === 118 && command.parameters[0] === label) {
            this.jumpTo(i);
            return;
        }
    }
    return true;
};

})();
As a side, I'm quite interested to know why the original function uses this._params[0]. What's going on when the game calls the function?

Code:
Game_Interpreter.prototype.executeCommand = function() {
    var command = this.currentCommand();
    if (command) {
        this._params = command.parameters;

this._params is an array of all the parameters for each event command. _params[0] is the name of the label that the developer entered in the Jump to Label command.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-make-labels-variable.84899/