function seems to work through console.log?

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
hey guys,

Im currently experimenting with functions in rpg maker mv, and ive stumbled upon something that i dont understand.
Code:
◆Script:"use strict"
:      :var labelName = "6";
:      :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);
:      :  }
:      :};
◆Script:console.log(this.command115())
◆Label:5
◆Play SE:Blow3 (90, 100, 0)
the console.log script, which is for exit event processing(which returns true btw) seems to still end the event, even when its in console.log - While i thought that things in console.log() didnt have any impact besides showing the contents in console log? Could someone explain to me how this is possible?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,117
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
Just for ease of reference, let's have a look at the definition of command115:
Code:
// Exit Event Processing
Game_Interpreter.prototype.command115 = function() {
    this._index = this._list.length;
    return true;
};
It's primarily a method, in that it's used to produce an effect (by changing a variable). The _list property of Game_Interpreter is a list of all event commands in the currently-running event; _index keeps track of which one we're on at the moment. So what this command does is say "skip any further event commands in the list".

Now to your line of code:
<snip>
Code:
◆Script:console.log(this.command115())
Brackets work here like they do anywhere else: the stuff in the brackets is evaluated first. So the code runs command115, which happens to also return the value true. Thus the line becomes:
Code:
console.log(true);
So it prints true to the console. Then the interpreter goes to evaluate the next line, sees it's reached the end of the event (thanks to command115) and stops. :kaophew:

Typically console.log is used with static values and variables or "proper" functions, i.e. functions that just return a value and don't "do stuff" besides that, which is probably why you've only just encountered this kind of issue. =)


Edit: try this instead if you want to see the code behind the command:
Code:
console.log(this.command115);
No brackets after the command115 means it's treated as an object that doesn't require evaluation; this means the console.log will run immediately. The argument (this.command115) is implicitly converted into a [multi-line] string and we see the code appear in the console. Success! :kaojoy:
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Easy.
console.log(this.command115())
You had these brackets there, so you called that function.
Remove them and it should work.
 

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top