Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RMMV ใส่คำสั่งในตัวเลือกจาก addCommand ยังไงครับ
#1
มีคำถามครับบ คำสั่งต้องการให้เกิดจากตัวเลือกที่สร้างจาก addCommand ต้องใส่ที่ไหนครับ ลองแกะไฟล์ rpg_scene, rpg_window เขียนตามแล้วไม่ได้อะครับ

Code:
//=====
// Choose Motherland Scenes
//=====

/*:
* @plugindesc Display Motherland Scenes. Use for project Ornearth only.
* @author Pannxe (irpg.in.th/user-1284.html)
*/

function Scene_pxeChooseHomeland() {
    this.initialize.apply(this, arguments);
}

Scene_pxeChooseHomeland.prototype = Object.create(Scene_MenuBase.prototype);
Scene_pxeChooseHomeland.prototype.constructor = Scene_pxeChooseHomeland;

Scene_pxeChooseHomeland.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};
Scene_pxeChooseHomeland.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createHeadWindow();
    this.createMotherlandWindow();
};
Scene_pxeChooseHomeland.prototype.createHeadWindow = function() {
    this._HeadWindow = new Window_Head(0,0);
    this.addWindow(this._HeadWindow);
}
Scene_pxeChooseHomeland.prototype.createMotherlandWindow = function() {
    this._MotherlandWindow = new Window_MotherlandList(0,0);
    this._MotherlandWindow.y = Graphics.boxHeight - this._MotherlandWindow.height;
    this.addWindow(this._MotherlandWindow);
}
Scene_pxeChooseHomeland.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
};
Scene_pxeChooseHomeland.prototype.update = function() {
    Scene_MenuBase.prototype.update.call(this);
    if (Input.isTriggered('cancel')) {
        SoundManager.playCancel();
        SceneManager.goto(Scene_Map);
    }
};

//------------------

Scene_pxeChooseHomeland.prototype.createCommandWindow = function() {
    this._motherlandListWindow = new Window_MotherlandList(0, 0);
    this._motherlandListWindow.setHandler('syrin',      this.commandSyrin.bind(this));
    this._motherlandListWindow.setHandler('dinyard',    this.commandDinyard.bind(this));
    this._motherlandListWindow.setHandler('cancel',     this.popScene.bind(this));
    this.addWindow(this._motherlandListWindow);

};

Scene_pxeChooseHomeland.prototype.commandSyrin = function() {
    DataManager.setupNewGame();
    this._commandWindow.close();
    this.fadeOutAll();
    SceneManager.goto(Scene_Map);

};

Scene_pxeChooseHomeland.prototype.commandDinyard = function() {
    /*
        .
        .
        .
    */
};

//=================================================
// Windows
//=================================================

//Head

function Window_Head() {
    this.initialize.apply(this, arguments);
}

Window_Head.prototype = Object.create(Window_Base.prototype);
Window_Head.prototype.constructor = Window_Head;

Window_Head.prototype.initialize = function(x, y) {
    var width = this.windowWidth();
    var height = this.windowHeight();
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
};

Window_Head.prototype.windowWidth = function() {
    return Graphics.width;
};

Window_Head.prototype.windowHeight = function() {
    return this.fittingHeight(1);
};

Window_Head.prototype.refresh = function() {
    var x = this.textPadding();
    var width = this.contents.width - this.textPadding() * 2;
    this.contents.clear();
    this.drawTextEx("Please choose your motherland.", 0, 0);
};

Window_Head.prototype.open = function() {
    this.refresh();
    Window_Base.prototype.open.call(this);
};

//------------------
//
//Homeland list

function Window_MotherlandList() {
    this.initialize.apply(this, arguments);
}

Window_MotherlandList.prototype = Object.create(Window_Command.prototype);
Window_MotherlandList.prototype.constructor = Window_MotherlandList;

Window_MotherlandList.prototype.initialize = function(x, y) {
    Window_Command.prototype.initialize.call(this, x, y);
    this.selectLast();
};

Window_MotherlandList._lastCommandSymbol = null;

Window_MotherlandList.initCommandPosition = function() {
    this._lastCommandSymbol = null;
};
Window_MotherlandList.prototype.windowWidth = function() {
    return 240;
};
Window_MotherlandList.prototype.numVisibleRows = function() {
    return this.maxItems();
};
Window_MotherlandList.prototype.makeCommandList = function() {
    this.addMainList();
};
Window_MotherlandList.prototype.addMainList = function() {
        this.addCommand("Syrin", 'syrin');
        this.addCommand('Dinyard', 'dinyard');
        this.addCommand('Logout', 'cancel');
};
Window_MotherlandList.prototype.areMainCommandsEnabled = function() {
    return $gameParty.exists();
};
Window_MotherlandList.prototype.processOk = function() {
    Window_MotherlandList._lastCommandSymbol = this.currentSymbol();
    Window_Command.prototype.processOk.call(this);
};
Window_MotherlandList.prototype.selectLast = function() {
    this.selectSymbol(Window_MotherlandList._lastCommandSymbol);
};

/puke/puke/puke/puke
งั่ม
Reply
#2
เขียนยังมั่วๆอยู่นะครับ แต่ก็ยังพอแก้ได้ แมวเบิกบาน

1.ท่านสร้างฟังก์ชันซ้อนกัน 2 ฟังก์ชัน โดยมี 1 ฟังก์ชันที่ไม่ทำงาน
ฟังก์ชันที่ซ้อนกันคือ createCommandWindow กับ createMotherlandWindow ของคลาส Scene_pxeChooseHomeland
  • ซึ่งคุณฟังก์ชัน createMotherlandWindow เนี่ย!! มันไม่มีการ setHandler เพราะงั้นกดให้ตายก็ไม่ขึ้น
  • ส่วนฟังก์ชัน createCommandWindow นั้นมัน setHandler ไว้แล้ว แต่ไม่ได้กำหนดคำแหน่งหน้าต่าง X Y (เอาจริงๆตรงคำสั่ง new Window_MotherlandList(0, 0) นั้น 0,0 คือพารามิเตอร์สำหรับกำหนดตำแหน่ง X,Y แต่อาจจะใช้ไม่ได้ ในกรณีของท่านที่ต้องรอให้มีการสร้าง Window ก่อน )

ท่านก็เพิ่ม this._motherlandListWindow.y = Graphics.boxHeight - this._motherlandListWindow.height;
ไว้ใต้บรรทัด this._motherlandListWindow = new Window_MotherlandList(0, 0); ก็พอ จะได้ประมาณนี้

Code:
Scene_pxeChooseHomeland.prototype.createCommandWindow = function() {
    this._motherlandListWindow = new Window_MotherlandList(0, 0);
    this._motherlandListWindow.y = Graphics.boxHeight - this._motherlandListWindow.height;
    this._motherlandListWindow.setHandler('syrin',      this.commandSyrin.bind(this));
    this._motherlandListWindow.setHandler('dinyard',    this.commandDinyard.bind(this));
    this._motherlandListWindow.setHandler('cancel',     this.popScene.bind(this));
    this.addWindow(this._motherlandListWindow);
};

แล้วก็ลบฟังก์ชัน createMotherlandWindow ทิ้งไปได้เลยครับ ไม่ได้ใช้แล้ว




2.ให้มาดูฟังก์ชัน create ของ Scene_pxeChooseHomeland
ตรงนี้เนื่องจากเราลบ ฟังก์ชัน createMotherlandWindow ไปแล้ว


ให้ท่านลบ this.createMotherlandWindow(); ตามไปด้วยเลยครับ แล้วเพิ่ม
this.createCommandWindow(); เข้าไปแทน จะได้ประมาณนี้
Code:
Scene_pxeChooseHomeland.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createHeadWindow();
    this.createCommandWindow();
};




3. ทีนี้จะเกิด Error ไม่รู้ close อัลไล เพราะมี window ที่ไม่มีตัวตน (undefined) ปรากฏขึ้น
ในฟังก์ชัน commandSyrin นั่นคือ this._commandWindow.close(); ง่วง
ต้องถามคนเขียนโค้ด Derp ว่าตัวแปร _commandWindow มันมาตอนไหน


แก้เป็น this._motherlandListWindow.close(); ครับ จะได้ประมาณนี้
Code:
Scene_pxeChooseHomeland.prototype.commandSyrin = function() {
    DataManager.setupNewGame();
    this._motherlandListWindow.close();
    this.fadeOutAll();
    SceneManager.goto(Scene_Map);
};

คำแนะนำ
1.ควรศึกษาการเขียนโปรแกรมเชิงวัตถุ OOP (Object-oriented programming) เพื่อความเข้าใจภาษา JavaScript มากขึ้น (ถ้าเรียนมาแล้วขออภัยดว้ยครับ ง่วง)
2.ควรศึกษาภาษา JavaScript ครับ
3.ควรศึกษาโครงสร้างเอนจิ้นของ RPG Maker MV นี้ก่อนครับ (ข้อนี้ประกอบกับข้อ 1 สำคัญมาก แพนด้าจ๊าก) เพราะว่าบางฟังก์ชันมันมีในคลาสแม่ สืบทอดมาคลาสลูก แต่บางฟังก์ชันก็ไม่มี ต้องดูให้ดีๆ เพราะ

พวก OOP มันจะมีตัวแปร instance ที่ใช้งานได้เฉพาะในคลาส (นอกคลาสเรียกใช้ไม่ได้) คือพวกที่เป็นตัวแปร _ ทั้งหลาย เช่น _motherlandListWindow เป็นต้น (JavaScript อาจจะเรียกใช้ได้ ผมไม่แน่ใจว่ามันมี scope หรือเปล่า เพราะ JavaScript มันชอบทำอะไรแปลกๆ เช่น ออกแบบมาเขียนโปรแกรมที่ทำงานแบบ Async) และเรื่องอื่นๆ

ก็ฝากไว้เพียงเท่านี้ละกันครับ เอ้าดื่ม
[-] The following 2 users say Thank You to XthemeCore for this post:
  • dreamknight, kumpan2000
Reply
#3
บรรจงกราบงามๆครับ
งั่ม
Reply
#4
;3

ขุ่นพระ ท่าน x เทพจริมๆๆ แพนด้าจ๊าก
May the flames guide your way. Every ending will make you stronger.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)