Is there way to use JS code in another JS

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?
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.
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
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.
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.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-way-to-use-js-code-in-another-js.85068/