how use LABEL in script call ?

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
hi guys how use Label in script call ???


I would like to jump to a dynamic label.
Example:


// Get de file name of picture


A = $gameScreen._pictures[$gameVariables.value(2)]._name;


// Convert A to string


A=String(A);


// and now jump to label A


$jumpTo(A);
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
Look at the game interpreter. That's what processes all commands so that's how you can see how to do it. I don't remember offhand but I think it just moved the current index and indent values in the interpreter until it found a matching label. 
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
I wanted to do the same thing a while ago, so I took the original, modified it and created a function:


Game_Interpreter.prototype.jump_to_label = function(label) {
for (var i = 0; i < this._list.length; i++) {
var command = this._list;
if (command.code === 118 && command.parameters[0] === label) {
this.jumpTo(i);
return;
}
}
return true;
}
//the script call will be
jump_to_label(label)


You can find the original functions in Game_Interpreter, just as zalerinian said. I put it in spoilers below for convenience.

Code:
// Jump to Label
Game_Interpreter.prototype.command119 = function() {
    var labelName = this._params[0];
    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;
};

Game_Interpreter.prototype.jumpTo = function(index) {
    var lastIndex = this._index;
    var startIndex = Math.min(index, lastIndex);
    var endIndex = Math.max(index, lastIndex);
    var indent = this._indent;
    for (var i = startIndex; i <= endIndex; i++) {
        var newIndent = this._list[i].indent;
        if (newIndent !== indent) {
            this._branch[indent] = null;
            indent = newIndent;
        }
    }
    this._index = index;
};
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
Look at the game interpreter. That's what processes all commands so that's how you can see how to do it. I don't remember offhand but I think it just moved the current index and indent values in the interpreter until it found a matching label. 
yes i look it but am nothing understant how to use in script call.

Code:
// Jump to Label
Game_Interpreter.prototype.command119 = function() {
    var labelName = this._params[0];
    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;
};
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
Well, one thing you can probably do is directly set the parameters array to the label name you want, an then call "this.command119();", which will run that code. I didn't test it, it's just the first thing I'd think to try if I needed to do this.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,669
First Language
German
Primarily Uses
RMMV
Modern Programming language usually don't use labels or goto's anymore due to ineffectiveness and other problems, the label is purely on the event level of execution.


Please describe exactly what you want to do, then we can point you into the direction on how to solve your problem.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top