MZ Creating Window_Selectable immediately executes "ok"

Hello,

I hope this is the correct section for my question. If not, I am sorry.

At first I'm quite new to the maker "game". But I have some experience in scripting and programming. Thats why I'm trying to create my own plugin very soon.

For my plugin, I first perform a character selection. This is working very good. But after that I'm creating a new "Window_Selectable" window. This immediately executes its own "ok" event. The user has no chance to select anything.

What I also found out is that this will only happen if I am using my keyboard. If I am using the mouse everything is working fine.

This is my Code:

Open a new Window:
Window_OurAct.prototype.checkClassWithTeacher = function(actorObj) { if (actorObj._classId == TeackerClassID) { var rec = new Rectangle(); rec.height = 600; rec.width = 800; rec.x = 0; rec.y = 0; var myWindow2 = new Window_RXSkillList(rec); myWindow2.show(); this.close(); SceneManager._scene.addWindow(myWindow2); } else { alert("some test message"); } };

initializing the new window:

function Window_RXSkillList() { this.initialize(...arguments); } Window_RXSkillList.prototype = Object.create(Window_Selectable.prototype); Window_RXSkillList.prototype.constructor = Window_RXSkillList; Window_RXSkillList.prototype.initialize = function(rect) { Window_Selectable.prototype.initialize.call(this, rect); this._actor = $gameActors.actor(2); this._stypeId = 1; this.avSkillList = [$dataSkills[141], $dataSkills[142]]; this._data = []; this.refresh(); this.hide(); this.setHandler("ok", this.onOK.bind(this)); this.activate(); };


Maybe anyone has an idea to solve this 🙂
Thank you in advance.

Greetings RoPurX

*If needed I can post the complete plugin script. But I thought it is a bit too much Code.
Can you show me the scene code where you instantiate it? (if you look at the default scripts, you usually call setHandler from the scene rather than doing it in the window initialize, but that by itself shouldn't be causing your issue)
Hello Trihan

thank you for your answer 🙂

This is the code. As you can see I'm Testing at the moment to understand the system.

I'm using the plugin command "Testen" to trigger the window.

At first I'm using the window "Window_OurAct". The user can choose an actor and after that the window "Window_RXSkillList" is opening to choose a skill.

Thank you

Greetings

RoPurX

JavaScript:
/*
 *
 */
 

//=============================================================================
// Metadata
//=============================================================================
/*:
 * @target MZ
 * @plugindesc Testing windows
 * @author RoPurX
 * @url none
 *
 * @command Testen
 * @text Testen
 * @desc Used to Test ;D
 /*
 *
 *
 * @help Version 1.2.2
 * ============================================================================
 * Plugin Commands
 * ============================================================================
 * Testen
 *      Just Testing
 */

let TeackerClassID = 2;

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

Window_OurAct.prototype = Object.create(Window_MenuStatus.prototype);
Window_OurAct.prototype.constructor = Window_OurAct;

Window_OurAct.prototype.initialize = function(rect) {
    Window_MenuStatus.prototype.initialize.call(this, rect);
    this.select(0);
    this.hide();
    this.activate();
    this.setHandler("ok", this.onOK.bind(this));
};

Window_OurAct.prototype.onOK = function() {
    var actorObj = $gameParty.members()[this.index()];
   
    /*let actorID = actorObj._actorId;
    let actorName = actorObj._name;
    let actorClassID = actorObj._classId;*/
   
    this.checkClassWithTeacher(actorObj);
};

Window_OurAct.prototype.checkClassWithTeacher = function(actorObj) {
    if (actorObj._classId == TeackerClassID) {
        var rec = new Rectangle();
        rec.height = 600;
        rec.width = 800;
        rec.x = 0;
        rec.y = 0;
       
       
        var myWindow2 = new Window_RXSkillList(rec);
        myWindow2.show();
        this.close();
        SceneManager._scene.addWindow(myWindow2);
    } else {
        alert("Pff du bist zu dumm dazu");
    }
};

Window_OurAct.prototype.processOk = function() {
    if (!this.cursorAll()) {
        $gameParty.setTargetActor($gameParty.members()[this.index()]);
    }
    this.callOkHandler();
};

Window_OurAct.prototype.selectLast = function() {
    this.forceSelect($gameParty.targetActor().index() || 0);
};

Window_OurAct.prototype.selectForItem = function(item) {
    const actor = $gameParty.menuActor();
    const action = new Game_Action(actor);
    action.setItemObject(item);
    this.setCursorFixed(false);
    this.setCursorAll(false);
    if (action.isForUser()) {
        if (DataManager.isSkill(item)) {
            this.setCursorFixed(true);
            this.forceSelect(actor.index());
        } else {
            this.selectLast();
        }
    } else if (action.isForAll()) {
        this.setCursorAll(true);
        this.forceSelect(0);
    } else {
        this.selectLast();
    }
};


/*
Skill List
*/

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

Window_RXSkillList.prototype = Object.create(Window_Selectable.prototype);
Window_RXSkillList.prototype.constructor = Window_RXSkillList;

Window_RXSkillList.prototype.initialize = function(rect) {
    Window_Selectable.prototype.initialize.call(this, rect);
    this._actor = $gameActors.actor(2);
    this._stypeId = 1;
    this.avSkillList = [$dataSkills[141], $dataSkills[142]];
    this._data = [];
    this.refresh();
    this.hide();
    this.setHandler("ok", this.onOK.bind(this));
    this.activate();
};

Window_RXSkillList.prototype.setActor = function(actor) {
    if (this._actor !== actor) {
        this._actor = actor;
        this.refresh();
        this.scrollTo(0, 0);
    }
};

Window_RXSkillList.prototype.onOK = function() {
    var actorObj = $gameParty.members()[this.index()];
    var test = this.avSkillList[this.index()];
    debugger;
    alert(this.avSkillList[this.index()].name);
    /*let actorID = actorObj._actorId;
    let actorName = actorObj._name;
    let actorClassID = actorObj._classId;*/
};

Window_RXSkillList.prototype.setStypeId = function(stypeId) {
    if (this._stypeId !== stypeId) {
        this._stypeId = stypeId;
        this.refresh();
        this.scrollTo(0, 0);
    }
};

Window_RXSkillList.prototype.maxCols = function() {
    return 2;
};

Window_RXSkillList.prototype.colSpacing = function() {
    return 16;
};

Window_RXSkillList.prototype.maxItems = function() {
    return this._data ? this._data.length : 1;
};

Window_RXSkillList.prototype.item = function() {
    return this.itemAt(this.index());
};

Window_RXSkillList.prototype.itemAt = function(index) {
    return this._data && index >= 0 ? this._data[index] : null;
};

Window_RXSkillList.prototype.isCurrentItemEnabled = function() {
    return this.isEnabled(this._data[this.index()]);
};

Window_RXSkillList.prototype.includes = function(item) {
    return item && item.stypeId === this._stypeId;
};

Window_RXSkillList.prototype.isEnabled = function(item) {
    return true;
};

Window_RXSkillList.prototype.makeItemList = function() {
   
    if (this._actor) {
        //this._data = this._actor.skills().filter(item => this.includes(item));
        this._data = this.avSkillList;
    } else {
        this._data = [];
    }
};

Window_RXSkillList.prototype.selectLast = function() {
    const index = this._data.indexOf(this._actor.lastSkill());
    this.forceSelect(index >= 0 ? index : 0);
};

Window_RXSkillList.prototype.drawItem = function(index) {
    const skill = this.itemAt(index);
    if (skill) {
        const costWidth = this.costWidth();
        const rect = this.itemLineRect(index);
        //this.changePaintOpacity(this.isEnabled(skill));
        this.drawItemName(skill, rect.x, rect.y, rect.width);
        //this.drawSkillCost(skill, rect.x, rect.y, rect.width);
        this.changePaintOpacity(1);
    }
};

Window_RXSkillList.prototype.costWidth = function() {
    return this.textWidth("000");
};

Window_RXSkillList.prototype.drawSkillCost = function(skill, x, y, width) {
    if (this._actor.skillTpCost(skill) > 0) {
        this.changeTextColor(ColorManager.tpCostColor());
        this.drawText(this._actor.skillTpCost(skill), x, y, width, "right");
    } else if (this._actor.skillMpCost(skill) > 0) {
        this.changeTextColor(ColorManager.mpCostColor());
        this.drawText(this._actor.skillMpCost(skill), x, y, width, "right");
    }
};

Window_RXSkillList.prototype.updateHelp = function() {
    this.setHelpWindowItem(this.item());
};

Window_RXSkillList.prototype.refresh = function() {
    this.makeItemList();
    Window_Selectable.prototype.refresh.call(this);
};



(() => {
   
    const PLUGIN_NAME = "testWin";
    const Test = "Testen";
   
    // Just for testing
    PluginManager.registerCommand(PLUGIN_NAME, Test, function (args) {
        var rec = new Rectangle();
        rec.height = 600;
        rec.width = 800;
        rec.x = 0;
        rec.y = 0;
       
        var myWindow = new Window_OurAct(rec);
        myWindow.show();
        SceneManager._scene.addWindow(myWindow);
    });
   
})();

Original thread: https://forums.rpgmakerweb.com/threads/creating-window_selectable-immediately-executes-ok.137992/