JavaScript questions that don't deserve their own thread

Hi all, I would like to know if there is a tutorial for the scrollable Windows MZ. Cause I really need one right now. Seems my brain can't compute this. Ive found some post in the forum but didn't really give concreat exemple of how to set them up. I've look into the core files, doing some experiments but can't figure out anything about this. I'll be gratefull for some help. Thx
Would my HTML code in JavaScript, created for my Blogger blog, work as a script in RPG Maker MV?
Hope my question make sense. I'm looking for a script call that's asking 'If the user that is currently acting has X state do XYZ'
This is context-dependent. My first suggestions, without plugins, would be:
  • BattleManager._subject - battler who is currently acting (action phase).
  • BattleManager.actor() - actor who is currently inputting (input phase).
For even more detail, i'm using SRD Timed attack core, and just want the bar to move slower if the user casting has slow state for example.
That plugin seems to permit JS evals in its Speed field, so you could try something like:

Speed: BattleManager._subject.isStateAffected(123) ? 10 : 100
I.e. "if the acting battler has state ID 123, the value is 10, otherwise 100". 👋

Otherwise you might want to start a new thread in Plugin Support.


Hi all, I would like to know if there is a tutorial for the scrollable Windows MZ.
Depends on exactly what you want from it. Seems like it would be worth starting a thread in Learning JavaScript for this? As a quick summary...

The windows are defined in rmmz_windows.js and the scenes (which create, and assign handlers to, new instances of windows) are in rmmz_scenes.js. Window_Scrollable is a basis for creating display objects with scrollable content, but usually it's Window_Selectable or Window_Command that people want to build on. That way, you only really need to define the item/row/column count, selection handlers, and either drawItem or makeCommandList method, respectively: all the scroll/paint logic is done for you~


Would my HTML code in JavaScript, created for my Blogger blog, work as a script in RPG Maker MV?
JavaScript lets you manipulate HTML elements, and RPG Maker MV creates HTML games. Would your mystery JS work as-is in RPG Maker MV? You're in a much better position than anyone else to answer that question: try it and see!
This is context-dependent. My first suggestions, without plugins, would be:
  • BattleManager._subject - battler who is currently acting (action phase).
  • BattleManager.actor() - actor who is currently inputting (input phase).

That plugin seems to permit JS evals in its Speed field, so you could try something like:

Speed: BattleManager._subject.isStateAffected(123) ? 10 : 100

I.e. "if the acting battler has state ID 123, the value is 10, otherwise 100". 👋

Otherwise you might want to start a new thread in Plugin Support.



Depends on exactly what you want from it. Seems like it would be worth starting a thread in Learning JavaScript for this? As a quick summary...

The windows are defined in rmmz_windows.js and the scenes (which create, and assign handlers to, new instances of windows) are in rmmz_scenes.js. Window_Scrollable is a basis for creating display objects with scrollable content, but usually it's Window_Selectable or Window_Command that people want to build on. That way, you only really need to define the item/row/column count, selection handlers, and either drawItem or makeCommandList method, respectively: all the scroll/paint logic is done for you~



JavaScript lets you manipulate HTML elements, and RPG Maker MV creates HTML games. Would your mystery JS work as-is in RPG Maker MV? You're in a much better position than anyone else to answer that question: try it and see!

Thank you for your response, I've open a thread in the learning Javascript.
How would one call the actor a particular piece of equipment is equipped to?
I'm trying to create an accessory which has an effect that uses the wearer's current hp in a formula in the notes. Edit: I may have figured out a workaround, but this would still be useful to know.
How would one call the actor a particular piece of equipment is equipped to?
I'm trying to create an accessory which has an effect that uses the wearer's current hp in a formula in the notes. Edit: I may have figured out a workaround, but this would still be useful to know.

$gameParty.members().some(actor => actor.hasArmor($dataArmors[1]))
to check whether any actor has this piece of armour

$gameParty.members().find(actor => actor.hasArmor($dataArmors[1])).hp
to get this actor's HP
Hopefully a quick one, using a state in MV with Yanfly States.

It works exactly as I want it to (gives 5 HP at turn end to all allies), but I've tried numerous things to get a damage pop-up to also trigger on everyone, but it always seems to not actually show.
Code:
<Custom Turn End Effect>
var cantorheal = 5;
user.friendsUnit().aliveMembers().forEach(ally => ally.gainHp(cantorheal));
user.friendsUnit().aliveMembers().startDamagePopup();
user.friendsUnit().aliveMembers().clearResult();
</Custom Turn End Effect>
How do I get the popup to happen? (I've tried a few things in line 3, I know it's wrong)
How do I get the popup to happen?
you still need to forEach() on the other lines. youre only doing it on the gainHp
you still need to forEach() on the other lines. youre only doing it on the gainHp
Could have sworn I tried that, but I think somehow I must have screwed it up (I think I didn't include the ally =>). It's fine now, thanks.
Code:
<Custom Turn End Effect>
var cantorheal = 5;
user.friendsUnit().aliveMembers().forEach(ally => ally.gainHp(cantorheal));
user.friendsUnit().aliveMembers().forEach(ally => ally.startDamagePopup());
user.friendsUnit().aliveMembers().forEach(ally => ally.clearResult());
</Custom Turn End Effect>
I am looking for help understanding why my javascript is not working as I expect. I have stripped the code down to the essential. It is supposed to allow you to select an item in battle through its own command and then log the item to console. It works to the point of selection, but then when the item is selected the code does not run the handler for the new window and instead runs the handler for the command window. It seems to me that the focus is never transferred to the new window, even though I am running .activate() on it. Is there an obvious error on my part? Is there a better place for me to look for help?

JavaScript:
    const _Alias_Window_ActorCommand_prototype_makeCommandList = Window_ActorCommand.prototype.makeCommandList;
    Window_ActorCommand.prototype.makeCommandList = function() {
        if (this._actor) {
            this.addNewCommand();
        }
        _Alias_Window_ActorCommand_prototype_makeCommandList.call(this);
    };

    Window_ActorCommand.prototype.addNewCommand = function() {
        this.addCommand("New", "new");
    };
    
    const _Alias_Scene_Battle_prototype_createActorCommandWindow = Scene_Battle.prototype.createActorCommandWindow;
    Scene_Battle.prototype.createActorCommandWindow = function() {
        _Alias_Scene_Battle_prototype_createActorCommandWindow.call(this);
        this._actorCommandWindow.setHandler("new", this.commandNew.bind(this));
    };

    Scene_Battle.prototype.commandNew = function() {
        this._newWindow.refresh();
        this._newWindow.show();
        this._newWindow.activate();
        this._newWindow.select(0);
        this._statusWindow.hide();
        this._actorCommandWindow.hide();
        this._actorCommandWindow.deactivate();
    };

    const _Alias_Scene_Battle_prototype_createAllWindows = Scene_Battle.prototype.createAllWindows;
    Scene_Battle.prototype.createAllWindows = function() {
        _Alias_Scene_Battle_prototype_createAllWindows.call(this);
        this.createNewWindow();
    };

    Scene_Battle.prototype.createNewWindow = function() {
        const rect = this.itemWindowRect();
        const NewWindow = new Window_New(rect);
        NewWindow.setHelpWindow(this._helpWindow);
        NewWindow.setHandler("ok", this.onNewOk.bind(this));
        NewWindow.setHandler("cancel", this.onNewCancel.bind(this));
        this.addWindow(NewWindow);
        this._newWindow = NewWindow;
    };

    Scene_Battle.prototype.onNewOk = function() {
        const item = this._newWindow.item();
        console.log(item);
        this.onNewCancel.call(this);
    };

    Scene_Battle.prototype.onNewCancel = function() {
        this._newWindow.hide();
        this._newWindow.deactivate();
        this._statusWindow.show();
        this._actorCommandWindow.refresh();
        this._actorCommandWindow.show();
        this._actorCommandWindow.activate();
    };

    //-----------------------------------------------------------------------------
    // Window_New
    //
    // The window for selecting an item to use on the battle screen.

    function Window_New() {
        this.initialize(...arguments);
    }

    Window_New.prototype = Object.create(Window_ItemList.prototype);
    Window_New.prototype.constructor = Window_New;

    Window_New.prototype.initialize = function(rect) {
        Window_ItemList.prototype.initialize.call(this, rect);
        this.hide();
    };

    Window_New.prototype.includes = function(item) {
        return item;
    };

    Window_New.prototype.show = function() {
        this.selectLast();
        this.showHelpWindow();
        Window_ItemList.prototype.show.call(this);
    };

    Window_New.prototype.hide = function() {
        this.hideHelpWindow();
        Window_ItemList.prototype.hide.call(this);
    };
@peetsnack Not 100% sure but wasn't that the case where the system activates your actor command window every frame. I think you need to modify this method to take into account your new window:

Scene_Battle.prototype.isAnyInputWindowActive = function() {
return (
this._partyCommandWindow.active ||
this._actorCommandWindow.active ||
this._skillWindow.active ||
this._itemWindow.active ||
this._actorWindow.active ||
this._enemyWindow.active
);
};

EDIT: Or some other method. I'm pretty sure there was some annoying pathway that kept activating the actor command window.
@peetsnack Not 100% sure but wasn't that the case where the system activates your actor command window every frame. I think you need to modify this method to take into account your new window:

Scene_Battle.prototype.isAnyInputWindowActive = function() {
return (
this._partyCommandWindow.active ||
this._actorCommandWindow.active ||
this._skillWindow.active ||
this._itemWindow.active ||
this._actorWindow.active ||
this._enemyWindow.active
);
};

EDIT: Or some other method. I'm pretty sure there was some annoying pathway that kept activating the actor command window.
That was it. All I had to do was add the following:
JavaScript:
const _Alias_Scene_Battle_prototype_isAnyInputWindowActive = Scene_Battle.prototype.isAnyInputWindowActive;
    Scene_Battle.prototype.isAnyInputWindowActive = function() {
        return _Alias_Scene_Battle_prototype_isAnyInputWindowActive.call(this) || this._newWindow.active;
    };

Thank you so much for the assistance. I have no idea how I could have figured that one out on my own.
How would one call the skill id of the action currently being executed?

I'm using Substitute Extend to have an actor intercept a specific skill.
BattleManager._action.item().id

But you might wanna make a check with something like this:
const action = BattleManager._action;
if (action && action.item() && action.isSkill() && action.item().id === X)
BattleManager._action.item().id

But you might wanna make a check with something like this:
const action = BattleManager._action;
if (action && action.item() && action.isSkill() && action.item().id === X)
This did the trick, thanks!
Hi all, I don't know if this question have already been ask so sorry if I make you repeat.
Ive come to see that changing an array base on another, change the original one and I'would like to know how I can work around so it change only the iteration.

Spoiler: exemple
JavaScript:
let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
console.log(arrayObj); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
let arrayObj2 = arrayObj;
console.log(arrayObj2); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
arrayObj2[1].a = 18;

For now the only solutions that I found are:

Spoiler: Solutions temps
JavaScript:
// isolate

let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
console.log(arrayObj); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj2 = arrayObj;
console.log(arrayObj2); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj3 = arrayObj2[0];
console.log(arrayObj3); //{a:2,b:45}
arrayObj3.a = 7;
console.log(arrayObj3); //{a:7,b:45}

// or mixing array

let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
console.log(arrayObj); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj2 = arrayObj;
console.log(arrayObj2); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj3 = [];
console.log(arrayObj3); // [{a:7,b:45},{a:5,b:265},{a:6,b:5}]
let modifier = [7,5,6,2,9,4,1]
for (let i = 0; i < arrayObj.length; i++) {
  arrayObj3[i] = {a: modifier[i], b:arrayObj2[i].b}
}

So if some less burdersome solutions exist I'll be glad to know.
Hi all, I don't know if this question have already been ask so sorry if I make you repeat.
Ive come to see that changing an array base on another, change the original one and I'would like to know how I can work around so it change only the iteration.

Spoiler: exemple
JavaScript:
let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
console.log(arrayObj); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
let arrayObj2 = arrayObj;
console.log(arrayObj2); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
arrayObj2[1].a = 18;

For now the only solutions that I found are:

Spoiler: Solutions temps
JavaScript:
// isolate

let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
console.log(arrayObj); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj2 = arrayObj;
console.log(arrayObj2); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj3 = arrayObj2[0];
console.log(arrayObj3); //{a:2,b:45}
arrayObj3.a = 7;
console.log(arrayObj3); //{a:7,b:45}

// or mixing array

let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
console.log(arrayObj); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj2 = arrayObj;
console.log(arrayObj2); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
let arrayObj3 = [];
console.log(arrayObj3); // [{a:7,b:45},{a:5,b:265},{a:6,b:5}]
let modifier = [7,5,6,2,9,4,1]
for (let i = 0; i < arrayObj.length; i++) {
  arrayObj3[i] = {a: modifier[i], b:arrayObj2[i].b}
}

So if some less burdersome solutions exist I'll be glad to know.
The structuredClone method creates deep copies, so maybe give that a try.
It'd look something like this:

JavaScript:
var arr1 = [{a: 0, b:0}];
var arr2 = structuredClone(arr1);
console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 0, b:0}]
arr2[0].a = 4;
console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 4, b:0}]
EDIT: sorry, I forgot objects retain their original references when shallow copying. This works instead!
The structuredClone method creates deep copies, so maybe give that a try.
It'd look something like this:

JavaScript:
var arr1 = [{a: 0, b:0}];
var arr2 = structuredClone(arr1);
console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 0, b:0}]
arr2[0].a = 4;
console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 4, b:0}]
EDIT: sorry, I forgot objects retain their original references when shallow copying. This works instead!
Thx a lot it's perfect, I didn't know this method.
In MZ, how would I make items non-stackable? For instance, if the player has 2 potions it gets split into 2 separate potion items? I'm trying to do a limited inventory thing.

Original thread: https://forums.rpgmakerweb.com/threads/javascript-questions-that-dont-deserve-their-own-thread.46341/