Is there way to use JS code in another JS

jackken123

Veteran
Veteran
Joined
Aug 24, 2017
Messages
81
Reaction score
8
First Language
Chinese
Primarily Uses
RMMV
Hi
I got a question.
I would like to use JS code in event page 3 "script"

I was using "Self Switches & Variables" by yanfly
http://yanfly.moe/2016/08/06/yep-113-self-switches-variables-rpg-maker-mv/
the plugin have a code
Code:
this.setSelfVariableValue(mapId, eventId, varId, value)
When I use the code itself without anyother code, it work.
But when I put it inside show choices code it fail

Code:
$gameMessage.add('Which one?');
$gameMessage.setChoices(['One', 'Two'], 0, -1);
$gameMessage.setChoiceCallback(
function (choice) {
if(choice === 0){
this.setSelfVariableValue(2, 5, 22, 1);//this one fail
};
if(choice === 1){};})
I know little about JS.
Can anyone tell me how to make this work?
 

dahlys

Meatbun
Veteran
Joined
Aug 28, 2017
Messages
95
Reaction score
99
First Language
English
Primarily Uses
RMMV
Code:
$gameSelfSwitches.setValue([mapId, eventId, 'SELF VARIABLE ' + varId], value);
Use the one above instead of this.setSelfVariableValue(mapId, eventId, varId, value). That command is inside Yanfly's code.

If you use this. inside $gameMessage, this. refers to game_message. To make Yanfly's script call work, this. must refer to game_interpreter.

May I ask why you are using script for show choices instead of the GUI? It would be much easier to do that, since you're on an event page instead of a plugin.
 
Last edited:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
yes you can but I advise against working this way.
example page 1
PHP:
myVariable25651256 = { // dont use var scope when declaring
// my stuff
}
page 2
PHP:
console.log(myVariable25651256);
//you will no have error because myVariable25651256 are now stored .window core game
but if you do like this in page 1 , paghe 2 will return error
PHP:
var myVariable25651256 = 85; // will not work because the var declaration will scope in the scriptCall only, and will destroy after script command
 

jackken123

Veteran
Veteran
Joined
Aug 24, 2017
Messages
81
Reaction score
8
First Language
Chinese
Primarily Uses
RMMV
Code:
$gameSelfSwitches.setValue([mapId, eventId, 'SELF VARIABLE ' + varId], value);
Use the one above instead of this.setSelfVariableValue(mapId, eventId, varId, value). That command is inside Yanfly's code.

If you use this. inside $gameMessage, this. refers to game_message. To make Yanfly's script call work, this. must refer to game_interpreter.

May I ask why you are using script for show choices instead of the GUI? It would be much easier to do that, since you're on an event page instead of a plugin.
Sorry for late.
I use script because I was learning script.
There's still a lot I don't know about JS.
And using script instead of event give me more experiences.
 

jackken123

Veteran
Veteran
Joined
Aug 24, 2017
Messages
81
Reaction score
8
First Language
Chinese
Primarily Uses
RMMV
yes you can but I advise against working this way.
example page 1
PHP:
myVariable25651256 = { // dont use var scope when declaring
// my stuff
}
page 2
PHP:
console.log(myVariable25651256);
//you will no have error because myVariable25651256 are now stored .window core game
but if you do like this in page 1 , paghe 2 will return error
PHP:
var myVariable25651256 = 85; // will not work because the var declaration will scope in the scriptCall only, and will destroy after script command
Thank you.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,040
Members
137,569
Latest member
Shtelsky
Top