RMMV How to improve my first PLUGIN? How to use it as a base for another one? (Picture into window issue)

basicleader

Veteran
Veteran
Joined
Oct 29, 2013
Messages
51
Reaction score
17
First Language
French
Hey everybody,

I took the time to go through the free JS course on Codecademy, and even though, I haven't mastered everything, it allowed me to finally try to create my first complete "big" plugin, and I actually got something pretty decent and working. This script is made to create Multiple Choice Questions tests for my pupils at school (It also adds a menu command in which I can see all their results afterwards). Here is the final code:

Code:
'use strict';
//=============================================================================
// Basic Teacher - TextMCQ Plugin Header - START
//-----------------------------------------------------------------------------
/*:
 * @plugindesc <BT_TextMCQ> TextMCQ Plugin
 * @author BasicTeacher
 * @help
 * Skill Level Calculation:
 *
 * For the skill level evaluation to work, you must have decided of the total
 * number of questions you will use in the whole textMCQ test.
 * From this, you must set the values of the different skill levels.
 * For example, if you have a total of 10 questions.
 *
 * You can set INS to 3 correct answers.
 * Pupils level is "INSUFFISANT" if he has 1, 2 or 3 correct answers.
 * You can set FRA to 6 correct answers.
 * Pupils level is "FRAGILE" if he has 4, 5, or 6 correct answers.
 * You can set SAT to 8 correct answers.
 * Pupils level is "SATISFAISANT" if he has 7 or 8 correct answers.
 * No need to setup anything for the highest level.
 * Pupils level is "TRES BONNE MAITRISE" if he has more than 8 correct answers.
 *
 * Add the possibility to use plugin commands to decide these values
 * before each test.
 *
 * Score Variable:
 *
 * Here, Choose the 'Score Variable' in which to save the pupil's test score.
 * (default: 100 / make sure you have created enough variables in the editor)
 * The value of this variable wil be used to keep the pupil's score during the
 * test and to evaluate the skill level of the pupil automatically by comparing
 * the pupil's score with the different Skill Level values entered above.
 *
 * If you start another test, you must first reset the Score Variable using the
 * following plugin command: BT_TextMCQ_scoreReset
 *
 * Results Variable:
 *
 * These variables will be used to keep the different Skill Level obtained
 * during the different textMCQ tests.
 * They will be displayed inside the In-game Menu: Menu > Text MCQ.
 * (default: from 101 to 109 / 9 different TextMCQtests maximum in one game)
 * The pupil's level will be displayed in a text message.
 *
 * MCQ Setup:
 *
 * Inside MCQ Setup, you must set each Question you want to use in the your test.
 * > Question: Type the question to which the pupil must answer.
 * > Choice n°1 to n°6: Type the different choices the pupil can choose from.
 * > The Right Choice: Decide which of the 6 choices is the right one.
 * > Correction: Type the correction to the question in case the pupil is wrong.
 *   It will appear as a text message every time the pupil makes a wrong choice.
 *
 * Once you have prepared all the test's questions, you must use the following
 * plugin command inside any event to display them in game:
 * BT_TextMCQ 1, BT_TextMCQ 2, BT_TextMCQ 3, etc...
 *
 * Praises - From 1 to 9:
 *
 * Here you can type the different praises that will be displayed randomly every
 * time the pupil chooses the right choice.
 *
 *
 *
 * Finally, here is the usual order in which the plugin commands will be used
 * inside an event:
 *
 * TextMCQ_ScoreReset => Resets the score in case it's not 0.
 * TextMCQ_ValueINS 3 => Sets a new value for the INSUFFISANT skill level.
 * TextMCQ_ValueFRA 6 => Sets a new value for the FRAGILE skill level.
 * TextMCQ_ValueSAT 8 => Sets a new value for the SATISFAISANT skill level.
 * TextMCQ 1 => Displays the 1st question set in MCQ Setup.
 * TextMCQ 2 => Displays the 2nd question set in MCQ Setup.
 * TextMCQ 3 => Displays the 3rd question set in MCQ Setup.
 * ...
 * BT_TextMCQ 10 => Displays the 10th question set in MCQ Setup.
 * BT_TextMCQ_Evaluation 5 => Launches the automatic skill level evaluation
 *                            Sets the variable in which the results is saved.
 *                            5 = variable 15
 *
 * All the results saved into these results variables can be displayed in the
 * In-Game menu: Menu > Text MCQ.
 *
 *
 * Special Thanks and Credits to Darkkitten for creating his cmdinp.js plugin.
 *
 * @param Evaluation
 * @text Skill Level Calculation
 * @default ---------------------------------
 *
 * @param INS
 * @parent Evaluation
 * @text Insuffisant
 * @desc below INS value, pupil's level is D.
 * @type number
 * @default 3
 *
 * @param FRA
 * @parent Evaluation
 * @text Fragile
 * @desc Between INS and FRA values, pupil's level is C.
 * @type number
 * @default 6
 *
 * @param SAT
 * @parent Evaluation
 * @text Satisfaisant
 * @desc Between FRA and SAT values, pupil's level is B. Above it's A!
 * @type number
 * @default 9
 *
 * @param scoreVariable
 * @text Score Variable
 * @desc The Variable the Score will be saved to. No need to change.
 * @type number
 * @default 10
 *
 * @param resultsVariable
 * @text Results Variable
 * @desc Users must setup the variable in which the MCQ results will be saved. No need to change.
 * @type number[]
 * @default [11, 12, 13, 14, 15, 16, 17, 18, 19]
 *
 * @param MCQSetup
 * @text MCQ Setup
 * @desc Users must setup each MCQ to use ingame before calling them through the plugin command.
 * @type struct<MCQSetup>[]
 * @default []
 *
 * @param praises
 * @text Praises
 * @default ---------------------------------
 *
 * @param P01
 * @parent praises
 * @text Praise 01
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P02
 * @parent praises
 * @text Praise 02
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P03
 * @parent praises
 * @text Praise 03
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P04
 * @parent praises
 * @text Praise 04
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P05
 * @parent praises
 * @text Praise 05
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P06
 * @parent praises
 * @text Praise 06
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P07
 * @parent praises
 * @text Praise 07
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P08
 * @parent praises
 * @text Praise 08
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 * @param P09
 * @parent praises
 * @text Praise 09
 * @desc A praise sentence used randomly when the pupil is right.
 * @type string
 * @default Good job! Keep going!
 *
 */

/*~struct~MCQSetup:
 * @param textQuestion
 * @text Question
 * @desc The question displayed inside the Question Window.
 * @type string
 * @default textHeader
 *
 * @param C01
 * @text Choice n°1
 * @desc Whatever the user wants to write as the first choice.
 * @type string
 * @default Choice n°1
 *
 * @param C02
 * @text Choice n°2
 * @desc Whatever the user wants to write as the second choice.
 * @type string
 * @default Choice n°2
 *
 * @param C03
 * @text Choice n°3
 * @desc Whatever the user wants to write as the third choice.
 * @type string
 * @default Choice n°3
 *
 * @param C04
 * @text Choice n°4
 * @desc Whatever the user wants to write as the fourth choice.
 * @type string
 * @default Choice n°4
 *
 * @param C05
 * @text Choice n°5
 * @desc Whatever the user wants to write as the fifth choice.
 * @type string
 * @default Choice n°5
 *
 * @param C06
 * @text Choice n°6
 * @desc Whatever the user wants to write as the sixth choice.
 * @type string
 * @default Choice n°6
 *
 * @param rightChoice
 * @text The Right Choice
 * @desc User must decide which choice is the correct one.
 * @type select
 * @option Choice n°1
 * @option Choice n°2
 * @option Choice n°3
 * @option Choice n°4
 * @option Choice n°5
 * @option Choice n°6
 *
 * @param correction
 * @text Correction
 * @desc If the pupil is wrong, it will display this correction in a message box.
 * @type string
 * @default Too bad!
 */
//-----------------------------------------------------------------------------
// Basic Teacher - TextMCQ Plugin Header - END
//=============================================================================

//=============================================================================
// Basic Plugin Setup + Parsing Parameters Functions - START
//-----------------------------------------------------------------------------

var Imported = Imported || {};
Imported.BT_TextMCQ_V2 = true;

var BT_TextMCQ = BT_TextMCQ || {};

function convertParameters (parameters) {
  function parseParameters (string) {
    try {
      return JSON.parse(string, (key, value) => {
        try {
          return parseParameters(value)
        } catch (e) {
          return value
        }
      })
    } catch (e) {
      return string
    }
  }
  return parseParameters(JSON.stringify(parameters))
};

var pluginParams = $plugins.filter(function(p) {
    return p.description.contains('<BT_TextMCQ>') && p.status;
})[0].parameters;

BT_TextMCQ.Param = convertParameters(pluginParams) || {};

//-----------------------------------------------------------------------------
// Basic Plugin Setup + Parsing Parameters Functions - END
//=============================================================================

//=============================================================================
// Plugin Parameters Setup - START
//-----------------------------------------------------------------------------

var getTextMCQ_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
    getTextMCQ_pluginCommand.call(this, command, args);

    if (command === "TextMCQ_scoreReset") {
        BT_TextMCQ.Param.varScore = BT_TextMCQ.Param.scoreVariable;
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, 0);
        console.log('Resetting the score variable');
    };

    if (command === "TextMCQ_INS") {
        if(args.length > 0 ) {
        BT_TextMCQ.Param.INS = Number(args[0]);
        console.log('INSvalue: ' + BT_TextMCQ.Param.INS);
        }
    };

    if (command === "TextMCQ_FRA") {
        if(args.length > 0 ) {
        BT_TextMCQ.Param.FRA = Number(args[0]);
        console.log('FRAvalue: ' + BT_TextMCQ.Param.FRA);
        }
    };
 
    if (command === "TextMCQ_SAT") {
        if(args.length > 0 ) {
        BT_TextMCQ.Param.SAT = Number(args[0]);
        console.log('SATvalue: ' + BT_TextMCQ.Param.SAT);
        }
    };

    if (command === "TextMCQ") {
        if(args.length > 0 ) {
            var Param_arg = Number(args[0] - 1);
       
            BT_TextMCQ.Param.varScore = BT_TextMCQ.Param.scoreVariable;

            BT_TextMCQ.Param.Question = BT_TextMCQ.Param.MCQSetup[Param_arg].textQuestion;

            BT_TextMCQ.Param.Choice01 = BT_TextMCQ.Param.MCQSetup[Param_arg].C01;
            BT_TextMCQ.Param.Choice02 = BT_TextMCQ.Param.MCQSetup[Param_arg].C02;
            BT_TextMCQ.Param.Choice03 = BT_TextMCQ.Param.MCQSetup[Param_arg].C03;
            BT_TextMCQ.Param.Choice04 = BT_TextMCQ.Param.MCQSetup[Param_arg].C04;
            BT_TextMCQ.Param.Choice05 = BT_TextMCQ.Param.MCQSetup[Param_arg].C05;
            BT_TextMCQ.Param.Choice06 = BT_TextMCQ.Param.MCQSetup[Param_arg].C06;
            BT_TextMCQ.Param.rightChoice = BT_TextMCQ.Param.MCQSetup[Param_arg].rightChoice;
            BT_TextMCQ.Param.correction = BT_TextMCQ.Param.MCQSetup[Param_arg].correction;

            BT_TextMCQ.Param.Praise01 = BT_TextMCQ.Param.P01;
            BT_TextMCQ.Param.Praise02 = BT_TextMCQ.Param.P02;
            BT_TextMCQ.Param.Praise03 = BT_TextMCQ.Param.P03;
            BT_TextMCQ.Param.Praise04 = BT_TextMCQ.Param.P04;
            BT_TextMCQ.Param.Praise05 = BT_TextMCQ.Param.P05;
            BT_TextMCQ.Param.Praise06 = BT_TextMCQ.Param.P06;
            BT_TextMCQ.Param.Praise07 = BT_TextMCQ.Param.P07;
            BT_TextMCQ.Param.Praise08 = BT_TextMCQ.Param.P08;
            BT_TextMCQ.Param.Praise09 = BT_TextMCQ.Param.P09;

            SceneManager.push(Scene_MCQuestion);
     
        }
    };

    if (command === "TextMCQ_Evaluation") {
        BT_TextMCQ.Param.varScore = BT_TextMCQ.Param.scoreVariable;
        if ($gameVariables.value(BT_TextMCQ.Param.varScore) <= BT_TextMCQ.Param.INS) {
            var resultsPrint = 'INSUFFISANT';
            console.log(resultsPrint);
        } else if ($gameVariables.value(BT_TextMCQ.Param.varScore) > BT_TextMCQ.Param.INS && $gameVariables.value(BT_TextMCQ.Param.varScore) <= BT_TextMCQ.Param.FRA ) {
            var resultsPrint = 'FRAGILE';
            console.log(resultsPrint);
        } else if ($gameVariables.value(BT_TextMCQ.Param.varScore) > BT_TextMCQ.Param.FRA && $gameVariables.value(BT_TextMCQ.Param.varScore) <= BT_TextMCQ.Param.SAT ) {
            var resultsPrint = 'SATISFAISANT';
            console.log(resultsPrint);
        } else if ($gameVariables.value(BT_TextMCQ.Param.varScore) > BT_TextMCQ.Param.SAT) {
            var resultsPrint = 'TRES BONNE MAITRISE';
            console.log(resultsPrint);
        }
        if(args.length > 0 ) {
            var resultsVar = Number(args[0] - 1);
            if (resultsVar === 0) { $gameVariables.setValue(11, resultsPrint); }
            if (resultsVar === 1) { $gameVariables.setValue(12, resultsPrint); }
            if (resultsVar === 2) { $gameVariables.setValue(13, resultsPrint); }
            if (resultsVar === 3) { $gameVariables.setValue(14, resultsPrint); }
            if (resultsVar === 4) { $gameVariables.setValue(15, resultsPrint); }
            if (resultsVar === 5) { $gameVariables.setValue(16, resultsPrint); }
            if (resultsVar === 6) { $gameVariables.setValue(17, resultsPrint); }
            if (resultsVar === 7) { $gameVariables.setValue(18, resultsPrint); }
            if (resultsVar === 8) { $gameVariables.setValue(19, resultsPrint); }
        }
        $gameMessage.add("Your skill level is: "+ resultsPrint + ".\nYour results have been saved.\nYou can see all your results in the menu.\nGame Menu > Text MCQ");
        this.setWaitMode("message");
    };
};

//-----------------------------------------------------------------------------
// Plugin Parameters Setup - END
//=============================================================================

//=============================================================================
// Scene_MCQuestion - START
//
// Function to create the Scene_MCQuestion
//-----------------------------------------------------------------------------

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

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

Scene_MCQuestion.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_MCQuestion.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.QuestionWindow();
    this.ChoicesWindow();
};

Scene_MCQuestion.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
    this._editQuestionWindow.refresh();
};

Scene_MCQuestion.prototype.QuestionWindow = function() {
      this._editQuestionWindow = new Window_QuestionEdit();
      this.addWindow(this._editQuestionWindow);
};

Scene_MCQuestion.prototype.ChoicesWindow = function() {
    this._choicesWindow = new Window_AnswersList(this._editQuestionWindow);
    this._choicesWindow.setHandler('ok', this.onThatsAllFolks.bind(this));
    this.addWindow(this._choicesWindow);
};

Scene_MCQuestion.prototype.onThatsAllFolks = function() {
    this.popScene();
};

//-----------------------------------------------------------------------------
// Scene_MCQuestion - END
//=============================================================================

//=============================================================================
// Window_QuestionEdit - START
//
// The window to display the question the pupil must answer
//-----------------------------------------------------------------------------

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

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

Window_QuestionEdit.prototype.initialize = function() {
    var width = this.windowWidth();
    var height = this.windowHeight();
    var x = (Graphics.boxWidth - width) / 2;
    var y = (Graphics.boxHeight - (height + 432)) / 2;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.activate();
    this.refresh();
};

Window_QuestionEdit.prototype.lineHeight = function() {
    return 30;
};

Window_QuestionEdit.prototype.windowWidth = function() {
    return 730;
};

Window_QuestionEdit.prototype.windowHeight = function() {
    return this.fittingHeight(3);
};

Window_QuestionEdit.prototype.refresh = function() {
    this.contents.clear();
    this.contents.fontSize = 30;
    this.drawText(BT_TextMCQ.Param.Question, 0, this.lineHeight(), this.windowWidth() - 48, 'center')
};

//-----------------------------------------------------------------------------
// Window_QuestionEdit - END
//=============================================================================

//=============================================================================
// Window_AnswersList - START
//
// The window for selecting text characters on the input screen
//-----------------------------------------------------------------------------

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

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


Window_AnswersList.prototype.lineHeight = function() {
    return 60;
};

Window_AnswersList.prototype.initialize = function(editWindow) {
    var x = editWindow.x;
    var y = editWindow.y + editWindow.height + 32;
    var width = editWindow.width;
    var height = this.windowHeight();
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._editWindow = editWindow;
    this._page = 0;
    this._index = 0;
    this.refresh();
    this.updateCursor();
    this.activate();
};


Window_AnswersList.prototype.windowHeight = function() {
    return this.fittingHeight(6);
};

Window_AnswersList.prototype.maxCols = function() {
    return 1;
};

Window_AnswersList.prototype.maxItems = function() {
    return 6;
};

Window_AnswersList.prototype.itemRect = function(index) {
    var rect = new Rectangle();
    var maxCols = this.maxCols();
    rect.width = this.itemWidth();
    rect.height = this.itemHeight();
    rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
    rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
    return rect;
};

Window_AnswersList.prototype.refresh = function() {
    this.contents.clear();
    this.resetTextColor();
    this.contents.fontSize = 40;
    var rect = this.itemRect(0);
    this.drawText(BT_TextMCQ.Param.Choice01, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(1);
    this.drawText(BT_TextMCQ.Param.Choice02, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(2);
    this.drawText(BT_TextMCQ.Param.Choice03, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(3);
    this.drawText(BT_TextMCQ.Param.Choice04, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(4);
    this.drawText(BT_TextMCQ.Param.Choice05, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(5);
    this.drawText(BT_TextMCQ.Param.Choice06, rect.x, rect.y, rect.width, 'center');
};

Window_AnswersList.prototype.randomPraise = function() {
    $gameMap._interpreter.wait(20);
    var random = Math.floor(Math.random() * 8);
    console.log('random: ' + random);
    switch (random) {
        case 0:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise01+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 1:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise02+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 2:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise03+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 3:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise04+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 4:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise05+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 5:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise06+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 6:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise07+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 7:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise08+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 8:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise09+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
    };
    $gameMap._interpreter.wait(20);
}

Window_AnswersList.prototype.processOk = function() {
    var index = this.index();
    var right = BT_TextMCQ.Param.rightChoice;
    var correction = BT_TextMCQ.Param.correction;

    if (index === 0 && right === 'Choice n°1') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 1 && right === 'Choice n°2') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 2 && right === 'Choice n°3') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 3 && right === 'Choice n°4') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 4 && right === 'Choice n°5') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 5 && right === 'Choice n°6') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else {
        $gameMessage.add(correction);
        $gameMap._interpreter.setWaitMode('message');
    };

    if (this.isCurrentItemEnabled()) {
        this.playOkSound();
        this.deactivate();
        this.callOkHandler();
    } else {
        this.playBuzzerSound();
    }
    var score = $gameVariables.value(BT_TextMCQ.Param.varScore);
    console.log('score: ' + score);

};

//-----------------------------------------------------------------------------
// WINDOW_AnswersList - END
//=============================================================================

//=============================================================================
// Alias - Window_MenuCommand - START
//
// This is modifying the core window plugins handling the menu.
//-----------------------------------------------------------------------------

var Alias_Window_MenuCommand_makeCommandList = Window_MenuCommand.prototype.makeCommandList;
    Window_MenuCommand.prototype.makeCommandList = function() {
        this.addTextMCQCommand();
      Alias_Window_MenuCommand_makeCommandList.call(this);
    };

// Creating new function for the new menu command
Window_MenuCommand.prototype.addTextMCQCommand = function() {
        this.addCommand('Text MCQ', 'textMCQresults', true);
};

//-----------------------------------------------------------------------------
// Alias - Window_MenuCommand - END
//=============================================================================

//=============================================================================
// Alias - Scene_Menu_createCommandWindow - START
//
// This is modifying the core window plugins handling the menu.
//-----------------------------------------------------------------------------

var Alias_Scene_Menu_createCommandWindow = Scene_Menu.prototype.createCommandWindow;
    Scene_Menu.prototype.createCommandWindow = function() {
    Alias_Scene_Menu_createCommandWindow.call(this);
    this._commandWindow.setHandler('textMCQresults',    this.commandPersonal.bind(this));
};

//-----------------------------------------------------------------------------
// Alias - Scene_Menu_createCommandWindow - END
//=============================================================================

//=============================================================================
// Alias - Scene_Menu_commandPersonal - START
//
// This is modifying the core window plugins handling the menu.
//-----------------------------------------------------------------------------

var Alias_Scene_Menu_commandPersonal = Scene_Menu.prototype.commandPersonal;
    Scene_Menu.prototype.commandPersonal = function() {
    Alias_Scene_Menu_commandPersonal.call(this);
    switch (this._commandWindow.currentSymbol()) {
    case 'textMCQresults':
        SceneManager.push(Scene_TextMCQResults);
        break
    }
};

//-----------------------------------------------------------------------------
// Alias - Scene_Menu_commandPersonal - END
//=============================================================================

//=============================================================================
// Scene_TextMCQResults - START
//
// The scene for the TextMCQ Option screen.
//-----------------------------------------------------------------------------

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

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

Scene_TextMCQResults.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_TextMCQResults.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this._statusWindow = new Window_TextMCQResults();
    this._statusWindow.setHandler('cancel',   this.popScene.bind(this));
    this._statusWindow.setHandler('pagedown', this.nextActor.bind(this));
    this._statusWindow.setHandler('pageup',   this.previousActor.bind(this));
    this._statusWindow.reserveFaceImages();
    this.addWindow(this._statusWindow);
};

Scene_TextMCQResults.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
    this.refreshActor();
};

Scene_TextMCQResults.prototype.refreshActor = function() {
    var actor = this.actor();
    this._statusWindow.setActor(actor);
};

Scene_TextMCQResults.prototype.onActorChange = function() {
    this.refreshActor();
    this._statusWindow.activate();
};

//-----------------------------------------------------------------------------
// Scene_TextMCQResults - END
//=============================================================================

//=============================================================================
// Window_TextMCQResults
//
// The window for displaying all the results from the textMCQ tests.
//-----------------------------------------------------------------------------

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

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

Window_TextMCQResults.prototype.initialize = function() {
    var width = Graphics.boxWidth;
    var height = Graphics.boxHeight;
    Window_Selectable.prototype.initialize.call(this, 0, 0, width, height);
    this._actor = null;
    this.refresh();
    this.activate();
};

Window_TextMCQResults.prototype.setActor = function(actor) {
    if (this._actor !== actor) {
        this._actor = actor;
        this.refresh();
    }
};

Window_TextMCQResults.prototype.refresh = function() {
    this.contents.clear();
    if (this._actor) {
        var lineHeight = this.lineHeight();
        this.drawBlock1(lineHeight * 0);
        this.drawHorzLine(lineHeight * 4);
        this.drawBlock2(lineHeight * 5);
        this.drawHorzLine(lineHeight * 15);
    }
};

Window_TextMCQResults.prototype.drawBlock1 = function(y) {
    var lineHeight = this.lineHeight();
    this.drawActorFace(this._actor, 12, y);
    this.drawActorName(this._actor, 204, y + lineHeight * 0);
    this.drawActorClass(this._actor, 204, y + lineHeight * 1);
    this.drawActorNickname(this._actor, 204, y + lineHeight * 2);
    this.drawBasicInfo(456, y);
};

Window_TextMCQResults.prototype.drawBlock2 = function(y) {
    var lineHeight = this.lineHeight();
    this.drawText('Text MCQ n°1 Results: ' + $gameVariables.value(11), 48, y + lineHeight * 0);
    this.drawText('Text MCQ n°2 Results: ' + $gameVariables.value(12), 48, y + lineHeight * 1);
    this.drawText('Text MCQ n°3 Results: ' + $gameVariables.value(13), 48, y + lineHeight * 2);
    this.drawText('Text MCQ n°4 Results: ' + $gameVariables.value(14), 48, y + lineHeight * 3);
    this.drawText('Text MCQ n°5 Results: ' + $gameVariables.value(15), 48, y + lineHeight * 4);
    this.drawText('Text MCQ n°6 Results: ' + $gameVariables.value(16), 48, y + lineHeight * 5);
    this.drawText('Text MCQ n°6 Results: ' + $gameVariables.value(17), 48, y + lineHeight * 6);
    this.drawText('Text MCQ n°8 Results: ' + $gameVariables.value(18), 48, y + lineHeight * 7);
    this.drawText('Text MCQ n°9 Results: ' + $gameVariables.value(19), 48, y + lineHeight * 8);
};

Window_TextMCQResults.prototype.drawHorzLine = function(y) {
    var lineY = y + this.lineHeight() / 2 - 1;
    this.contents.paintOpacity = 48;
    this.contents.fillRect(0, lineY, this.contentsWidth(), 2, this.lineColor());
    this.contents.paintOpacity = 255;
};

Window_TextMCQResults.prototype.lineColor = function() {
    return this.normalColor();
};

Window_TextMCQResults.prototype.drawBasicInfo = function(x, y) {
    var lineHeight = this.lineHeight();
    this.drawActorLevel(this._actor, x, y + lineHeight * 0);
    this.drawActorIcons(this._actor, x, y + lineHeight * 1);
    this.drawActorHp(this._actor, x, y + lineHeight * 2);
    this.drawActorMp(this._actor, x, y + lineHeight * 3);
};

//-----------------------------------------------------------------------------
// Window_TextMCQResults - END
//=============================================================================

//-----------------------------------------------------------------------------
// Basic Teacher - TextMCQ Plugin - END OF CODE
//=============================================================================

First, It is working fine as it is, but I was wondering if people more experimented could spot places where I could improve the way I've coded things, or even obvious mistakes that should be avoided at all costs.


Second, I've been trying to base a second script out of this one, in which the pupil will have to choose between different pictures instead of text (words/sentences). I thought it would be a quick matter of switching all my "drawText" for some kind of "drawpicture" thing. But as I discover, handling pictures is not as straight-forward as putting text in a rectangle.

I went through all the threads I could find on the topic, and tried as many things as possible for 2 days, but the best I could manage was to display pictures, but all of them would appear at the same spot, in the area over the first rectangle (itemrect); contrary to the drawtext that I could easily put into each rectangles in my first plugin.

If anybody could find the reasons why I found it impossible to do, knowing that this new plugin is just based off the first one, I'm mainly making experiments in this area:

Code:
Window_AnswersList.prototype.itemRect = function(index) {
    var rect = new Rectangle();
    var maxCols = this.maxCols();
    rect.width = this.itemWidth();
    rect.height = this.itemHeight();
    rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
    rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
    return rect;
};

Window_AnswersList.prototype.refresh = function() {
    this.contents.clear();
    this.resetTextColor();
    this.contents.fontSize = 40;
    var rect = this.itemRect(0);
    this.drawText(BT_TextMCQ.Param.Choice01, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(1);
    this.drawText(BT_TextMCQ.Param.Choice02, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(2);
    this.drawText(BT_TextMCQ.Param.Choice03, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(3);
    this.drawText(BT_TextMCQ.Param.Choice04, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(4);
    this.drawText(BT_TextMCQ.Param.Choice05, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(5);
    this.drawText(BT_TextMCQ.Param.Choice06, rect.x, rect.y, rect.width, 'center');
};

Here are some examples of experiments I've kept:
1. NOT WORKING
Code:
Window_AnswersList.prototype.drawPicture = function(filename, x, y) {
    const bitmap = ImageManager.loadPicture(filename) // This will load the filename inside the Img/pictures folder
    bitmap.addLoadListener(() => { // This is a method that will run a callback when the bitmap is loaded
        this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y) // This will draw the bitmap on the contents of the window.
    })
};

Window_AnswersList.prototype.refresh = function() {
    this.contents.clear();
    this.resetTextColor();
    this.contents.fontSize = 40;
    var rect = this.itemRect(0);
    //this.drawText(BT_TextMCQ.Param.Choice01, rect.x, rect.y, rect.width, 'center');
    this.drawPicture("airplane");
    var rect = this.itemRect(1);
    this.drawText(BT_TextMCQ.Param.Choice02, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(2);
    this.drawText(BT_TextMCQ.Param.Choice03, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(3);
    this.drawText(BT_TextMCQ.Param.Choice04, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(4);
    this.drawText(BT_TextMCQ.Param.Choice05, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(5);
    this.drawText(BT_TextMCQ.Param.Choice06, rect.x, rect.y, rect.width, 'center');
};

2. The one displaying images but impossible to put each picture in each rectangle:

Code:
Window_AnswersList.prototype.itemRect = function(index) {
    var rect = new Rectangle();
    var maxCols = this.maxCols();
    rect.width = this.itemWidth();
    rect.height = this.itemHeight();
    rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
    rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
    return rect;
};

Window_AnswersList.prototype.drawC01 = function(x, y, pc1) {
    this.contents.blt(pc1, 0, 0, this.itemWidth(), this.itemHeight(), x, y);
};

Window_AnswersList.prototype.drawC02 = function(x, y, pc2) {
    this.contents.blt(pc2, 0, 0, this.itemWidth(), this.itemHeight(), x, y);
};

Window_AnswersList.prototype.refresh = function() {
    this.contents.clear();
    var rect = this.itemRect(0);
    var pc1 = ImageManager.loadPicture(BT_TextMCQ.Param.Choice01);
    pc1.addLoadListener(this.drawC01.bind(this, 0, 0));
    var rect = this.itemRect(1);
    var pc2 = ImageManager.loadPicture(BT_TextMCQ.Param.Choice02);
    pc2.addLoadListener(this.drawC02.bind(this, 0, 0));
    var rect = this.itemRect(2);

    var rect = this.itemRect(3);

};

Thanks everyone!
 
Last edited:

Mac15001900

Veteran
Veteran
Joined
Aug 7, 2022
Messages
76
Reaction score
51
First Language
English
Primarily Uses
RMMV
First, It is working fine as it is, but I was wondering if people more experimented could spot places where I could improve the way I've coded things, or even obvious mistakes that should be avoided at all costs.
I've had a quick glance at it, and while nothing the "should be avoided at all costs", there are definitely some things you can do to make the code more readable and more easily expandable.

In general, you're doing a lot of copy-pasting the same instruction when you want to do a lot of a similar thing. This will make it more cumbersome to read or edit the code, either for someone else who'd like to use it, or for you a year from now you'll want to make some changes to it. For example, instead of this:
JavaScript:
var resultsVar = Number(args[0] - 1);
if (resultsVar === 0) { $gameVariables.setValue(11, resultsPrint); }
if (resultsVar === 1) { $gameVariables.setValue(12, resultsPrint); }
if (resultsVar === 2) { $gameVariables.setValue(13, resultsPrint); }
if (resultsVar === 3) { $gameVariables.setValue(14, resultsPrint); }
if (resultsVar === 4) { $gameVariables.setValue(15, resultsPrint); }
if (resultsVar === 5) { $gameVariables.setValue(16, resultsPrint); }
if (resultsVar === 6) { $gameVariables.setValue(17, resultsPrint); }
if (resultsVar === 7) { $gameVariables.setValue(18, resultsPrint); }
if (resultsVar === 8) { $gameVariables.setValue(19, resultsPrint); }
You could do
JavaScript:
var resultsVar = Number(args[0] - 1);
$gameVariables.setValue(11+resultsVar , resultsPrint);
Which is a lot faster to read and to edit.

I'd also highly recommend doing a tutorial on arrays and for loops - they are really useful for storing multiple similar things or doing multiple similar actions, and there are a lot of places where the plugin could definitely use them.

If you're planning on making this available to people, then please disable all console.log instances - easiest way will be to just comment them out, or ideally provide a "debug" parameter in your plugin that allows you to turn them on/off. Otherwise those can get a bit annoying if you're trying to debug something else.

But overall, great job! This is a fairly impressive plugin, especially for a beginner.

Unfortunately I can't really help with images, I haven't really played with that part of the engine (and sadly it is barely documented).
 

basicleader

Veteran
Veteran
Joined
Oct 29, 2013
Messages
51
Reaction score
17
First Language
French
I've had a quick glance at it, and while nothing the "should be avoided at all costs", there are definitely some things you can do to make the code more readable and more easily expandable.

In general, you're doing a lot of copy-pasting the same instruction when you want to do a lot of a similar thing. This will make it more cumbersome to read or edit the code, either for someone else who'd like to use it, or for you a year from now you'll want to make some changes to it. For example, instead of this:
JavaScript:
var resultsVar = Number(args[0] - 1);
if (resultsVar === 0) { $gameVariables.setValue(11, resultsPrint); }
if (resultsVar === 1) { $gameVariables.setValue(12, resultsPrint); }
if (resultsVar === 2) { $gameVariables.setValue(13, resultsPrint); }
if (resultsVar === 3) { $gameVariables.setValue(14, resultsPrint); }
if (resultsVar === 4) { $gameVariables.setValue(15, resultsPrint); }
if (resultsVar === 5) { $gameVariables.setValue(16, resultsPrint); }
if (resultsVar === 6) { $gameVariables.setValue(17, resultsPrint); }
if (resultsVar === 7) { $gameVariables.setValue(18, resultsPrint); }
if (resultsVar === 8) { $gameVariables.setValue(19, resultsPrint); }
You could do
JavaScript:
var resultsVar = Number(args[0] - 1);
$gameVariables.setValue(11+resultsVar , resultsPrint);
Which is a lot faster to read and to edit.

I'd also highly recommend doing a tutorial on arrays and for loops - they are really useful for storing multiple similar things or doing multiple similar actions, and there are a lot of places where the plugin could definitely use them.

If you're planning on making this available to people, then please disable all console.log instances - easiest way will be to just comment them out, or ideally provide a "debug" parameter in your plugin that allows you to turn them on/off. Otherwise those can get a bit annoying if you're trying to debug something else.

But overall, great job! This is a fairly impressive plugin, especially for a beginner.

Unfortunately I can't really help with images, I haven't really played with that part of the engine (and sadly it is barely documented).
Thanks for your feedback, it's motivating me to keep learning ahead. From what I could remember from the free JS course I took on Codacademy, I had guessed I'd have to go back there and dig up the loops stuff that I couldn't master on that first go; now you've added arrays to that to-do list, I'll make sure to practice both in the coming weeks.

Thanks for all the great advice, will definitely put them into practice.

As for the picture issue, while waiting for other people's feedback, I'm going to create a simpler window plugin in which experimenting will be easier until I find a solution. If I do, I'll see if that solution can be applied to this plugin without breaking anything!

Thanks again, wish you the best Mac!
 

basicleader

Veteran
Veteran
Joined
Oct 29, 2013
Messages
51
Reaction score
17
First Language
French
Hi everyone,
After playing around in another plugin, I found the culprit. However, I must say I don't really understand what is going on in this code, I feel more like I'm completely back to the time where I was tweaking without any JS knowledge, anyway, here is the working code:
JavaScript:
Window_AnswersList.prototype.drawC01 = function(pc1) {
    var rect = this.itemRect(0);
    this.contents.blt(pc1, 0, 0, this.itemWidth(), this.itemHeight(), rect.x, rect.y);
};

Window_AnswersList.prototype.drawC02 = function(pc2) {
    var rect = this.itemRect(1);
    this.contents.blt(pc2, 0, 0, this.itemWidth(), this.itemHeight(), rect.x, rect.y);
};

Window_AnswersList.prototype.drawC03 = function(pc3) {
    var rect = this.itemRect(2);
    this.contents.blt(pc3, 0, 0, this.itemWidth(), this.itemHeight(), rect.x, rect.y);
};

Window_AnswersList.prototype.drawC04 = function(pc4) {
    var rect = this.itemRect(3);
    this.contents.blt(pc4, 0, 0, this.itemWidth(), this.itemHeight(), rect.x, rect.y);
};

Window_AnswersList.prototype.refresh = function() {
    this.contents.clear();
    var pc1 = ImageManager.loadPicture(BT_TextMCQ.Param.Choice01);
    pc1.addLoadListener(this.drawC01.bind(this));
    var pc2 = ImageManager.loadPicture(BT_TextMCQ.Param.Choice02);
    pc2.addLoadListener(this.drawC02.bind(this));
    var pc3 = ImageManager.loadPicture(BT_TextMCQ.Param.Choice03);
    pc3.addLoadListener(this.drawC03.bind(this));
    var pc4 = ImageManager.loadPicture(BT_TextMCQ.Param.Choice04);
    pc4.addLoadListener(this.drawC04.bind(this));
};

Defining rect in each Draw function, I could move all the pictures that I knew how to load to their right spots in the window selectable. I guess it's enough but I feel pretty frustrated for now.

Anyway, I still have a lot to study with loops and arrays for now.

My first invitation to check out how I can improve my plugin still holds.
First, It is working fine as it is, but I was wondering if people more experimented could spot places where I could improve the way I've coded things, or even obvious mistakes that should be avoided at all costs.
If anybody comes around! Thanks everyone!
 

basicleader

Veteran
Veteran
Joined
Oct 29, 2013
Messages
51
Reaction score
17
First Language
French
I've had a quick glance at it, and while nothing the "should be avoided at all costs", there are definitely some things you can do to make the code more readable and more easily expandable.

In general, you're doing a lot of copy-pasting the same instruction when you want to do a lot of a similar thing. This will make it more cumbersome to read or edit the code, either for someone else who'd like to use it, or for you a year from now you'll want to make some changes to it. For example, instead of this:
JavaScript:
var resultsVar = Number(args[0] - 1);
if (resultsVar === 0) { $gameVariables.setValue(11, resultsPrint); }
if (resultsVar === 1) { $gameVariables.setValue(12, resultsPrint); }
if (resultsVar === 2) { $gameVariables.setValue(13, resultsPrint); }
if (resultsVar === 3) { $gameVariables.setValue(14, resultsPrint); }
if (resultsVar === 4) { $gameVariables.setValue(15, resultsPrint); }
if (resultsVar === 5) { $gameVariables.setValue(16, resultsPrint); }
if (resultsVar === 6) { $gameVariables.setValue(17, resultsPrint); }
if (resultsVar === 7) { $gameVariables.setValue(18, resultsPrint); }
if (resultsVar === 8) { $gameVariables.setValue(19, resultsPrint); }
You could do
JavaScript:
var resultsVar = Number(args[0] - 1);
$gameVariables.setValue(11+resultsVar , resultsPrint);
Which is a lot faster to read and to edit.

I'd also highly recommend doing a tutorial on arrays and for loops - they are really useful for storing multiple similar things or doing multiple similar actions, and there are a lot of places where the plugin could definitely use them.

If you're planning on making this available to people, then please disable all console.log instances - easiest way will be to just comment them out, or ideally provide a "debug" parameter in your plugin that allows you to turn them on/off. Otherwise those can get a bit annoying if you're trying to debug something else.

But overall, great job! This is a fairly impressive plugin, especially for a beginner.

Unfortunately I can't really help with images, I haven't really played with that part of the engine (and sadly it is barely documented).
I took the time to review these array and loops, and I think I could simplify my plugin in 3 different places! Thanks again!


Code:
Window_AnswersList.prototype.refresh = function() {
    this.contents.clear();
    this.resetTextColor();
    this.contents.fontSize = 40;

    //IMPROVED CODE
    for (var i = 0; i < 7; i++) {
        var rect = this.itemRect(i);
        this.drawText(BT_TextMCQ.Param.Choices[i], rect.x, rect.y, rect.width, 'center');
    }


    /* OLD CODE
    var rect = this.itemRect(0);
    this.drawText(BT_TextMCQ.Param.Choice01, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(1);
    this.drawText(BT_TextMCQ.Param.Choice02, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(2);
    this.drawText(BT_TextMCQ.Param.Choice03, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(3);
    this.drawText(BT_TextMCQ.Param.Choice04, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(4);
    this.drawText(BT_TextMCQ.Param.Choice05, rect.x, rect.y, rect.width, 'center');
    var rect = this.itemRect(5);
    this.drawText(BT_TextMCQ.Param.Choice06, rect.x, rect.y, rect.width, 'center');
    */
};

Window_AnswersList.prototype.randomPraise = function() {
    //IMPROVED CODE Test
    var praiseArray = BT_TextMCQ.Param.Praises;
    //console.log(praiseArray);
    var praiseIndex = Math.floor(Math.random() * praiseArray.length);
    //console.log(praiseIndex);
    $gameMap._interpreter.wait(20);
    $gameMessage.add(""+BT_TextMCQ.Param.Praises[praiseIndex]+"");
    $gameMap._interpreter.setWaitMode('message');
    $gameMap._interpreter.wait(20);

    /* OLD CODE VERSION
    switch (random) {
        case 0:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise01+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 1:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise02+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 2:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise03+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 3:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise04+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 4:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise05+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 5:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise06+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 6:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise07+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 7:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise08+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
        case 8:
        $gameMessage.add(""+BT_TextMCQ.Param.Praise09+"");
        $gameMap._interpreter.setWaitMode('message');
        break;
    };
    */

}

Window_AnswersList.prototype.processOk = function() {
    
    // IMPROVED CODE VERSION
    var index = this.index() + 1;
    //console.log(index);
    var right = BT_TextMCQ.Param.rightChoice;
    //console.log(right);
    var correction = BT_TextMCQ.Param.correction;
    if (index === right) {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else {
        $gameMessage.add(correction);
        $gameMap._interpreter.setWaitMode('message');
    };

    /* OLD CODE VERSION

    if (index === 0 && right === 'Choice n°1') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 1 && right === 'Choice n°2') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 2 && right === 'Choice n°3') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 3 && right === 'Choice n°4') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 4 && right === 'Choice n°5') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else if (index === 5 && right === 'Choice n°6') {
        $gameVariables.setValue(BT_TextMCQ.Param.varScore, $gameVariables.value(BT_TextMCQ.Param.varScore) + 1);
        this.randomPraise();
    } else {
        $gameMessage.add(correction);
        $gameMap._interpreter.setWaitMode('message');
    };

    */

    if (this.isCurrentItemEnabled()) {
        this.playOkSound();
        this.deactivate();
        this.callOkHandler();
    } else {
        this.playBuzzerSound();
    }
    //var score = $gameVariables.value(BT_TextMCQ.Param.varScore);
    //console.log('score: ' + score);

};

Also commented out all the console.log in case I share the plugin once I'm completely done!
 

Latest Profile Posts

So I managed to scare my chief. Between shifts I had an appointment with my psychiatrist, so prior to it I'd told him "If I ain't coming today, they've kept me there.". Then as I was asleep, my phone died. So I overslept and through the entire time I was unreachable.
I spent so much time toiling in VX Ace frankensteining scripts together only for MV to come along and just... have everything.

The overworld tool system in particular I thought was gonna take me a million years to recreate, but nope. Thanks Moghunter.
Going to go live way earlier than usual tonight, pretty much in 20 minutes, purely because I'm bored. :LZSlol:

So... I'm gonna be a parent... XD

Forum statistics

Threads
128,379
Messages
1,194,065
Members
168,877
Latest member
eternaldes
Top