Hi everybody!
I'm playing around with script modding/making but I'm still a begginer.
I'm stuck now with this problem: Is it impossible to assign a plugin's parameter value to a variable?
I mean, I have set up my parameters properly, I use a plugin command to trigger my plugin's parameters.
I can get all their respective values from the console without any problem, but if I try to assign them to a variable inside my plugin to reuse it in my code, it always returns "undefined" in the console and is thus unusable as well in my code.
I hope there's a way to do that. If you have enough experience to help me on this! Thanks a lot.
Here's the code of my whole plugin if it can help:
You can search for my tests in the plugin, they all return "undefined" whatever I have tried to do:
var test = BT_TextMCQ.Param.argCheck;
var varId = BT_TextMCQ.Param.varId;
var maxLength = BT_TextMCQ.Param.maxLength;
var defaultPromptText = BT_TextMCQ.Param.defaultPromptText;
Thanks again everyone!
I'm playing around with script modding/making but I'm still a begginer.
I'm stuck now with this problem: Is it impossible to assign a plugin's parameter value to a variable?
I mean, I have set up my parameters properly, I use a plugin command to trigger my plugin's parameters.
I can get all their respective values from the console without any problem, but if I try to assign them to a variable inside my plugin to reuse it in my code, it always returns "undefined" in the console and is thus unusable as well in my code.
I hope there's a way to do that. If you have enough experience to help me on this! Thanks a lot.
Here's the code of my whole plugin if it can help:
JavaScript:
'use strict';
/*:
* @plugindesc <BT_TextMCQ> BasicTeacher - Text MCQ Plugin
* @author DarkKitten's cmdinp.js modified by BasicTeacher
* @help
* Users must setup the different MCQ windows they want to use inside ITV Setup.
*
* Each Input Window must have 4 informations:
* Choose the variable in which to save the input text.
* Enter the maximum number of characters the player can input.
* Enter the sentence you want to display in the input text window.
* Enter the words you want to display in the input bar if necessary.
* Enter the 6 choices available to answer the question.
*
* Use a plugin command inside any event to call the input windows.
* Plugin command: BT_TextMCQ <ITVSetup number>
* Example: BT_TextMCQ 0
* This example will call the Input Window you setup in ITV Setup first line.
* To call the second line, it would be BT_TextMCQ 1, etc...
*
* Note that this plugin is compatible with Quxios' QInput plugin.
*
* Special Thanks and Credits to Darkkitten for creating his command input plugin.
*
* @param ITVSetup
* @text ITV Setup
* @desc Users must setup each ITV to use ingame before calling them through the plugin command.
* @type struct<ITVSetup>[]
* @default []
*/
/*~struct~ITVSetup:
* @param scoreVariable
* @text Score Variable
* @desc the Variable the Score will be saved to.
* @type number
* @default 100
*
* @param maxCharacters
* @text Maximum Characters
* @desc Maximum number of Characters you can input.
* @type number
* @default 12
*
* @param textHeader
* @text Input window default header
* @desc The Default sentence displayed at the top of the Input Window.
* @type string
* @default textHeader
*
* @param textInput
* @text Input bar default text
* @desc The default text displayed in the Input bar if necessary.
* @type string
* @default
*
* @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
*/
var Imported = Imported || {};
Imported.InputTextToVariable = 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 plugin = $plugins.filter(function(p) {
return p.description.contains('<BT_TextMCQ>') && p.status
})[0];
BT_TextMCQ.Parameters = plugin.parameters;
BT_TextMCQ.Param = convertParameters(BT_TextMCQ.Parameters) || {};
var getMCQ_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
getMCQ_pluginCommand.call(this, command, args);
if (command === "BT_TextMCQ") {
if(args.length > 0 ) {
var ITV_arg = Number(args[0]);
console.log('argument: '+ ITV_arg);
console.log('scoreVariable: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].scoreVariable);
console.log('maxCharacters: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].maxCharacters);
console.log('textHeader: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].textHeader);
console.log('textInput: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].textInput);
console.log('Choice01: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].C01);
console.log('Choice02: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].C02);
console.log('Choice03: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].C03);
console.log('Choice04: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].C04);
console.log('Choice05: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].C05);
console.log('Choice06: ' + BT_TextMCQ.Param.ITVSetup[ITV_arg].C06);
BT_TextMCQ.Param.argCheck = ITV_arg;
$gameVariables.setValue(3, ITV_arg);
BT_TextMCQ.Param.varId = BT_TextMCQ.Param.ITVSetup[ITV_arg].scoreVariable;
BT_TextMCQ.Param.maxLength = BT_TextMCQ.Param.ITVSetup[ITV_arg].maxCharacters;
BT_TextMCQ.Param.defaultPromptText = BT_TextMCQ.Param.ITVSetup[ITV_arg].textHeader;
BT_TextMCQ.Param.defaultInputText = BT_TextMCQ.Param.ITVSetup[ITV_arg].textInput;
BT_TextMCQ.Param.Choice01 = BT_TextMCQ.Param.ITVSetup[ITV_arg].C01;
BT_TextMCQ.Param.Choice02 = BT_TextMCQ.Param.ITVSetup[ITV_arg].C02;
BT_TextMCQ.Param.Choice03 = BT_TextMCQ.Param.ITVSetup[ITV_arg].C03;
BT_TextMCQ.Param.Choice04 = BT_TextMCQ.Param.ITVSetup[ITV_arg].C04;
BT_TextMCQ.Param.Choice05 = BT_TextMCQ.Param.ITVSetup[ITV_arg].C05;
BT_TextMCQ.Param.Choice06 = BT_TextMCQ.Param.ITVSetup[ITV_arg].C06;
SceneManager.push(Scene_TextMCQ);
}
}
};
//-------------------------------------------------------------------------------------------
// Scene_TextMCQ
//
// Function to create the Scene_TextMCQ
//-------------------------------------------------------------------------------------------
function Scene_TextMCQ(){
this.initialize.apply(this, arguments);
}
var test = BT_TextMCQ.Param.argCheck;
var varId = BT_TextMCQ.Param.varId;
var maxLength = BT_TextMCQ.Param.maxLength;
var defaultPromptText = BT_TextMCQ.Param.defaultPromptText;
//Constructors
Scene_TextMCQ.prototype = Object.create(Scene_MenuBase.prototype);
Scene_TextMCQ.prototype.constructor = Scene_TextMCQ;
Scene_TextMCQ.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_TextMCQ.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.CEW();
this.CIW();
};
Scene_TextMCQ.prototype.start = function() {
Scene_MenuBase.prototype.start.call(this);
this._editTextWindow.refresh();
};
Scene_TextMCQ.prototype.CEW = function() {
this._editTextWindow = new Window_TextEdit();
this.addWindow(this._editTextWindow);
};
Scene_TextMCQ.prototype.CIW = function() {
this._inputTextWindow = new Window_AnswersList(this._editTextWindow);
this.addWindow(this._inputTextWindow);
};
Scene_TextMCQ.prototype.onThatsJustFine = function() {
var str = this._editTextWindow.finaltext();
var re = new RegExp(str, "i");
$gameVariables.setValue(BT_TextMCQ.Param.varId, re.source);
BT_TextMCQ.Param.defaultPromptText = '';
this.popScene();
};
//-------------------------------------------------------------------------------------------
// Window_TextEdit
//
// The window for editing the Text on the input screen.
//-------------------------------------------------------------------------------------------
function Window_TextEdit() {
this.initialize.apply(this, arguments);
}
Window_TextEdit.prototype = Object.create(Window_Base.prototype);
Window_TextEdit.prototype.constructor = Window_TextEdit;
Window_TextEdit.prototype.initialize = function() {
var width = this.windowWidth();
var height = this.windowHeight();
var x = (Graphics.boxWidth - width) / 2;
var y = (Graphics.boxHeight - (height + this.fittingHeight(9) + 8)) / 2;
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.defaultText = BT_TextMCQ.Param.defaultInputText;
if (this.defaultText === null)
{
this.defaultText = $gameVariables[BT_TextMCQ.Param.varId];
}
this._text = this.defaultText.slice(0, BT_TextMCQ.Param.maxLength);
console.log(this._text);
this._index = this._text.length;
this.activate();
this.refresh();
};
//-------------------------------------------------------------------------------------------
// Mod: Making the TextEdit windowWidth slightly bigger to fit the screen
//-------------------------------------------------------------------------------------------
Window_TextEdit.prototype.windowWidth = function() {
return 730;
};
//-------------------------------------------------------------------------------------------
// Mod: Making the TextEdit windowHeight slightly smaller
//-------------------------------------------------------------------------------------------
Window_TextEdit.prototype.windowHeight = function() {
return this.fittingHeight(3);
};
Window_TextEdit.prototype.finaltext = function() {
console.log(this._text);
return this._text;
};
Window_TextEdit.prototype.restoreDefault = function() {
var _text = this.defaultText;
this._index = this._text.length;
this.refresh();
console.log(this._text +" "+this.defaultText);
return this._text.length > 0;
};
Window_TextEdit.prototype.add = function(ch) {
var maxLength = BT_TextMCQ.Parameters.maxLength;
if (this._index < BT_TextMCQ.Param.maxLength) {
this._text += ch;
this._index++;
this.refresh();
return true;
} else {
return false;
}
};
Window_TextEdit.prototype.back = function() {
if (this._index > 0) {
this._index--;
this._text = this._text.slice(0, this._index);
this.refresh();
return true;
} else {
return false;
}
};
Window_TextEdit.prototype.charWidth = function() {
var text = $gameSystem.isJapanese() ? '\uff21' : 'A';
return this.textWidth(text);
};
Window_TextEdit.prototype.left = function() {
var textCenter = (this.contentsWidth() + this.DefaultTextWidth()) / 2;
var textWidth = (BT_TextMCQ.Param.maxLength + 2) * this.charWidth();
return Math.min(textCenter - textWidth / 2, this.contentsWidth() - textWidth);
};
Window_TextEdit.prototype.DefaultTextWidth = function(){
return (BT_TextMCQ.Param.maxLength + 40);
};
Window_TextEdit.prototype.itemRect = function(index) {
return {
x: this.left() + index * this.charWidth(),
y: 54,
width: this.charWidth(),
height: this.lineHeight()
};
};
Window_TextEdit.prototype.underlineRect = function(index) {
var rect = this.itemRect(index);
rect.x++;
rect.y += rect.height - 4;
rect.width -= 2;
rect.height = 2;
return rect;
};
Window_TextEdit.prototype.underlineColor = function() {
return this.normalColor();
};
Window_TextEdit.prototype.drawUnderline = function(index) {
var rect = this.underlineRect(index);
var color = this.underlineColor();
this.contents.paintOpacity = 48;
this.contents.fillRect(rect.x, rect.y, rect.width, rect.height, color);
this.contents.paintOpacity = 255;
};
Window_TextEdit.prototype.drawChar = function(index) {
var rect = this.itemRect(index);
this.resetTextColor();
this.drawText(this._text[index] || '', rect.x, rect.y);
};
Window_TextEdit.prototype.refresh = function() {
this.contents.clear();
this.drawTextEx(BT_TextMCQ.Param.defaultPromptText, 0, this.lineHeight() - 25)
for (var i = 0; i < BT_TextMCQ.Param.maxLength; i++) {
this.drawUnderline(i);
}
for (var j = 0; j < this._text.length; j++) {
this.drawChar(j);
}
var rect = this.itemRect(this._index);
this.setCursorRect(rect.x, rect.y, rect.width, rect.height);
};
//-------------------------------------------------------------------------------------------
// Window_Selectable (Alias)
//
// The window class with cursor movement and scroll functions.
//
// Mod: Original function rewritten to allow for one touch action on the visual keyboard
//
//-------------------------------------------------------------------------------------------
BT_TextMCQ.alias = Window_Selectable.prototype.onTouch;
Window_Selectable.prototype.onTouch = function(triggered) {
BT_TextMCQ.alias.call (this);
var lastIndex = this.index();
var x = this.canvasToLocalX(TouchInput.x);
var y = this.canvasToLocalY(TouchInput.y);
var hitIndex = this.hitTest(x, y);
if (hitIndex >= 0) {
if (hitIndex === this.index()) {
if (triggered && this.isTouchOkEnabled()) {
this.processOk();
}
} else if (this.isCursorMovable()) {
this.select(hitIndex);
//-------------------------------------------------------------------------------------------
// Mod: this.processOk() is added below to allow one touch action on the visual keyboard
//-------------------------------------------------------------------------------------------
this.processOk();
}
} else if (this._stayCount >= 10) {
if (y < this.padding) {
this.cursorUp();
} else if (y >= this.height - this.padding) {
this.cursorDown();
}
}
if (this.index() !== lastIndex) {
SoundManager.playCursor();
}
};
//-------------------------------------------------------------------------------------------
// Window_AnswersList
//
// The window for selecting text characters on the input screen.
//
// Mod: This whole part has been modified to display my on-screen visual keyboard.
//
//-------------------------------------------------------------------------------------------
function Window_AnswersList() {
this.initialize.apply(this, arguments);
}
//var argId = $gameVariables.value(3);
var Choice01 = BT_TextMCQ.Param.ITVSetup[0].C01;
var Choice02 = BT_TextMCQ.Param.ITVSetup[0].C02;
var Choice03 = BT_TextMCQ.Param.ITVSetup[0].C03;
var Choice04 = BT_TextMCQ.Param.ITVSetup[0].C04;
var Choice05 = BT_TextMCQ.Param.ITVSetup[0].C05;
var Choice06 = BT_TextMCQ.Param.ITVSetup[0].C06;
//-------------------------------------------------------------------------------------------
// Mod: Creating a visual keyboard layout using ANSWERS
//-------------------------------------------------------------------------------------------
Window_AnswersList.prototype = Object.create(Window_Selectable.prototype);
Window_AnswersList.prototype.constructor = Window_AnswersList;
Window_AnswersList.ANSWERS =
[ Choice01, Choice02, Choice03, Choice04,Choice05, Choice06 ];
//-------------------------------------------------------------------------------------------
// Mod: Creating more vertical space between the visual keys (36 => 60)
//-------------------------------------------------------------------------------------------
Window_AnswersList.prototype.lineHeight = function() {
return 60;
};
Window_AnswersList.prototype.initialize = function(editWindow) {
var x = editWindow.x;
//-------------------------------------------------------------------------------------------
// Mod: Moving the visual keyboard window down (8 => 32)
//-------------------------------------------------------------------------------------------
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();
};
//-------------------------------------------------------------------------------------------
// Mod: Deciding the fitting height of the visual keyboard window
//-------------------------------------------------------------------------------------------
Window_AnswersList.prototype.windowHeight = function() {
return this.fittingHeight(6);
};
Window_AnswersList.prototype.table = function() {
return [Window_AnswersList.ANSWERS];
};
Window_AnswersList.prototype.maxCols = function() {
return 1;
};
//-------------------------------------------------------------------------------------------
// Mod: Bringing down the number of max characters to 50
// A few numbers had to be changed all around, easy to find though.
//-------------------------------------------------------------------------------------------
Window_AnswersList.prototype.maxItems = function() {
return 6;
};
Window_AnswersList.prototype.character = function() {
return this._index < 6 ? this.table()[this._page][this._index] : '';
};
//-------------------------------------------------------------------------------------------
// Mod: Capital Letters Function
//-------------------------------------------------------------------------------------------
/*
Window_AnswersList.prototype.isCapital = function() {
return this._index === 5;
};
//-------------------------------------------------------------------------------------------
// Mod: Erase Button Function
//-------------------------------------------------------------------------------------------
Window_AnswersList.prototype.isEraseBack = function() {
return this._index === 5;
};
Window_AnswersList.prototype.isOk = function() {
return this._index === 5;
};
*/
//SOLUTION FOUND
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() {
var table = this.table();
this.contents.clear();
this.resetTextColor();
for (var i = 0; i < 6; i++) {
var rect = this.itemRect(i);
//-------------------------------------------------------------------------------------------
// Mod: Realign the letter in the center of the key and resizing the key width
//-------------------------------------------------------------------------------------------
rect.x += 10;
rect.width -= 20;
//-------------------------------------------------------------------------------------------
// Mod: Change font size for the visual keyboard to 40
//-------------------------------------------------------------------------------------------
this.contents.fontSize = 40;
this.drawText(table[this._page][i], rect.x, rect.y, rect.width, 'center');
}
};
Window_AnswersList.prototype.updateCursor = function() {
var rect = this.itemRect(this._index);
this.setCursorRect(rect.x, rect.y, rect.width, rect.height);
};
Window_AnswersList.prototype.isCursorMovable = function() {
return this.active;
};
Window_AnswersList.prototype.cursorDown = function(wrap) {
if (this._index < 40 || wrap) {
this._index = (this._index + 10) % 90;
}
};
Window_AnswersList.prototype.cursorUp = function(wrap) {
if (this._index >= 10 || wrap) {
this._index = (this._index + 80) % 90;
}
};
Window_AnswersList.prototype.cursorRight = function(wrap) {
if (this._index % 10 < 9) {
this._index++;
} else if (wrap) {
this._index -= 9;
}
};
Window_AnswersList.prototype.cursorLeft = function(wrap) {
if (this._index % 10 > 0) {
this._index--;
} else if (wrap) {
this._index += 9;
}
};
Window_AnswersList.prototype.cursorPagedown = function() {
this._page = (this._page + 1) % this.table().length;
this.refresh();
};
Window_AnswersList.prototype.cursorPageup = function() {
this._page = (this._page + this.table().length - 1) % this.table().length;
this.refresh();
};
Window_AnswersList.prototype.processCursorMove = function() {
var lastPage = this._page;
Window_Selectable.prototype.processCursorMove.call(this);
this.updateCursor();
if (this._page !== lastPage) {
SoundManager.playCursor();
}
};
//-------------------------------------------------------------------------------------------
// Note: Qinput parameters must be set so that no interaction will occur with the on-screen
// keyboard
//-------------------------------------------------------------------------------------------
Window_AnswersList.prototype.processHandling = function() {
if (this.isOpen() && this.active) {
if (Imported.Quasi_Input || Imported.QInput){
if (Input.isTriggered('#enter')) {
if (this.isOk()){this.onTextOk();}
else{this.processJump();}
}
else if (Input.anyPressed("a-z0-9")) {
if (!Input.isPressed('#enter')){
this._editWindow.add(Input._lastPressed);
}
}
if (Input.isRepeated('#backspace')) {
this.processBack();
}
}else{
if (Input.isTriggered('shift')) {
this.processJump();
}
if (Input.isRepeated('cancel')) {
this.processBack();
}
if (Input.isRepeated('ok')) {
this.processOk();
}
}
}
};
Window_AnswersList.prototype.isCancelEnabled = function() {
return true;
};
Window_AnswersList.prototype.processCancel = function() {
this.processBack();
};
Window_AnswersList.prototype.processJump = function() {
if (this._index !== 49) {
this._index = 49;
SoundManager.playCursor();
}
};
Window_AnswersList.prototype.processBack = function() {
if (this._editWindow.back()) {
SoundManager.playCancel();
}
};
//-------------------------------------------------------------------------------------------
// Mod: ProcessOk + Capital Letters + Erase Button Functions
//-------------------------------------------------------------------------------------------
Window_AnswersList.prototype.processOk = function() {
if (this.character()) {
this.onTextAdd();
} else if (this.isCapital()) {
SoundManager.playOk();
this.cursorPagedown();
} else if (this.isEraseBack()) {
SoundManager.playOk();
this.processBack();
}else if (this.isOk()) {
this.onTextOk();
}
};
Window_AnswersList.prototype.onTextAdd = function() {
if (this._editWindow.add(this.character())) {
SoundManager.playOk();
} else {
SoundManager.playBuzzer();
}
};
Window_AnswersList.prototype.onTextOk = function() {
if (this._editWindow.finaltext() === '') {
if (this._editWindow.restoreDefault()) {
SoundManager.playOk();
} else {
SoundManager.playBuzzer();
}
} else {
SoundManager.playOk();
this.callOkHandler();
}
};
You can search for my tests in the plugin, they all return "undefined" whatever I have tried to do:
var test = BT_TextMCQ.Param.argCheck;
var varId = BT_TextMCQ.Param.varId;
var maxLength = BT_TextMCQ.Param.maxLength;
var defaultPromptText = BT_TextMCQ.Param.defaultPromptText;
Thanks again everyone!