Plugin Help - The game isn't recognizing any of the changes?

● ARCHIVED · READ-ONLY
Started by wrigty12 8 posts View original ↗
  1. I'm trying to form my first simple plugin (No JS experience, but I know general workings of a handful of other coding languages)

    This one is meant to transform how TP functions, specifically (in order of appearance in my code):

    All Actors in the Party sharing the same TP value at all times;

    Being able to change the Max TP through a variable;

    Making the TP bar adjust to the new Max TP;

    Being able to adjust the initial TP equation;

    Turn on or off the TP charge rate;

    However, my game (no other plugins on) does not recognize any of the changes I made.

    Help? :D

    Spoiler
    Code:
    //=============================================================================// TDW_TP_Changes.js//=============================================================================/*: * @plugindesc Makes some minor changes to how TP works. * @author Tyler Wright * * @param Max TP Variable ID * @desc The ID of the variable for storing the max TP you wish to have. Set to 0 to keep at default. * @default 0 * * @param Actors Share TP * @desc Should all Actors share the same TP? * NO - false     YES - true * @default false * * @param TP Gain on Damage * @desc Should Actors gain TP when damage is taken? * NO - false     YES - true * @default true * * @param Initial TP Equation * @desc Actors start battle with TP equal to this equation. Default: Math.randomInt(25) * @default Math.randomInt(25) * * @help This plugin does not provide plugin commands. */ (function() {	var parameters = PluginManager.parameters('TDW_TP_Changes');    var variableId = Number(parameters['Max TP Variable ID'] || 0);	var shareTP = String(parameters['Actors Share TP'] || 'false');	var chargeTP = String(parameters['TP Gain on Damage'] || 'true');	var initialTPEqn = Number(parameters['Initial TP Equation'] || 'Math.randomInt(25)');				//Shared TP	var _Game_BattlerBase_setTp = Game_BattlerBase.prototype.setTp;	Game_BattlerBase.prototype.setTp = function(tp) {		_Game_BattlerBase_setTp.call(this, tp);			if (eval(shareTP) && this.isActor()){			for (actor in $gameParty[]){			actor._tp = tp;			actor.refresh();			}		}else{			this._tp = tp;			this.refresh();		}	};		//TP Max Alterations	var _Game_BattlerBase_maxTp = Game_BattlerBase.prototype.maxTp;	Game_BattlerBase.prototype.maxTp = function() {		_Game_BattlerBase_maxTp.call(this);			if ($gameVariables.value(variableId).isInteger() && 		$gameVariables.value(variableId)!= 0){			return $gameVariables.value(variableID);		}else{			return 100;		}	};	//TP Bar Rate Alterations	var _Game_BattlerBase_tpRate = Game_BattlerBase.prototype.tpRate;	Game_BattlerBase.prototype.tpRate = function() {		_Game_BattlerBase_tpRate.call(this);			if ($gameVariables.value(variableId).isInteger() && 		$gameVariables.value(variableId)!= 0){			return return this.tp / $gameVariables.value(variableID);		}else{			return 100;		}	};	//TP Equation Alterations	var initialTP = eval(initialTPEqn);		var _Game_Battler_initTp = Game_Battler.prototype.initTp;	Game_Battler.prototype.initTp = function() {		_Game_Battler_initTp.call(this);			this.setTp(initialTP);	};		//TP Charge Rate Alterations	var _Game_Battler_chargeTpByDamage = Game_Battler.prototype.chargeTpByDamage;	Game_Battler.prototype.chargeTpByDamage = function(damageRate) {		_Game_Battler_chargeTpByDamage.call(this, damageRate);			var value = Math.floor(50 * damageRate * this.tcr);		if (eval(chargeTP)){			this.gainSilentTp(value);		}	};		})(); 
  2. Before diving deeper, just a few tips:

    You can press f8 to open the Console while testing your game.

    In the console, you can type $PluginManager to dump the plugins info, it should show all loaded plugins as enumerable objects. You should be able to see your plugin and its properties and such.

    Any console.log() you use in your code will also be displayed in this console window, useful for debugging.
  3. Thanks for the tip! But for me, its $plugins. $PluginManager is not defined, it says.
  4. Here's the initial couple problems that were preventing anything from happening at all:

    On line 46, $gameParty[] should be $gameParty()

    On line 76, you typed return twice.

    MV was catching these two errors and preventing the rest of the code from executing at all. I found a few more things while I was at it:

    On lines 61 and 74, 

    $gameVariables.value(variableId).isInteger()should be

    Number.isInteger($gameVariables.value(variableId))I notice you tend to use eval - this is (usually) seriously bad news in javascript. It's slow to process and can potentially create errors that are very difficult to debug. For cases where you have

    if(eval(shareTP))you can instead use

    if(shareTP)so long as the default value is false.  I saw one situation where you were genuinely using it to run a string as a function (for the initial TP calculation). I don't know of a workaround for that off the top of my head. In any case, it wasn't working - it always returned NaN.

    Speaking of the initial TP calculation, the syntax for generating a random number in javascript is Math.random(), which generates a random number between 0 and 1, rather than within a range of your choosing. However, the MSDN does have a number of examples you can look at to write a function that will give you a number between two values.

    It's good that you're aliasing, but the way you do it will not always work. For instance, consider your maxTp alias, where you call the original function and then put in your new code. Problem: this is the default code for maxTp.

    Game_BattlerBase.prototype.maxTp = function() { return 100;};So the original code immediately returns 100 and your code never has a chance to run.

    This is probably not everything, but I've spent all the time I can on this for now. If I get a chance later I'll look at it again. Hope this helped.
  5. Thanks a bunch!

    I know eval() is horrible, but I couldn't find any way around it (I was looking on other plugins that came with MV to find out what they did.)

    I tried just doing if(shareTP) and the other one, but it stopped working properly.. I also tried representing them with numbers, and I was getting a clamp error or something..

    But otherwise, here is a fully functional code! Give it a look over to see if there is anything that should be changed, otherwise it works just the way I want!

    Spoiler
    Code:
    //=============================================================================// TDW_TP_Changes.js//=============================================================================/*: * @plugindesc Makes some minor changes to how TP works. * @author Tyler Wright * * @param Max TP Variable ID * @desc The ID of the variable for storing the max TP you wish to have. Set to 0 to keep at default. * @default 0 * * @param Actors Share TP * @desc Should all Actors share the same TP? * NO - false     YES - true * @default false * * @param TP Gain on Damage * @desc Should Actors gain TP when damage is taken? * NO - false     YES - true * @default true * * @param Initial TP Equation * @desc Actors start battle with TP equal to this equation. Default = Math.randomInt(25) * @default Math.randomInt(25) * * @help This plugin does not provide plugin commands. */ (function() {	var parameters = PluginManager.parameters('TDW_TP_Changes');    var variableId = Number(parameters['Max TP Variable ID'] || 0);	var shareTP = String(parameters['Actors Share TP'] || 'false');	var chargeTP = String(parameters['TP Gain on Damage'] || 'true');	var initialTPEqn = String(parameters['Initial TP Equation']);		//Shared TP - GOOD	var _Game_BattlerBase_setTp = Game_BattlerBase.prototype.setTp;	Game_BattlerBase.prototype.setTp = function(tp) {		if (eval(shareTP) && this.isActor()){			var total = tp;			for (i=0; i < $gameParty.members().length; i++){				$gameParty.members()[i]._tp = total;				$gameParty.members()[i].refresh();			}		} else {			this._tp = tp;			this.refresh();		}	};		//TP Max Alterations - GOOD	var _Game_BattlerBase_maxTp = Game_BattlerBase.prototype.maxTp;	Game_BattlerBase.prototype.maxTp = function() {		_Game_BattlerBase_maxTp.call(this);			if (($gameVariables.value(variableId) % 1 === 0) && 		$gameVariables.value(variableId)!= 0){			return $gameVariables.value(variableId);		}else{			return 100;		}	};	//TP Bar Rate Alterations - GOOD	var _Game_BattlerBase_tpRate = Game_BattlerBase.prototype.tpRate;	Game_BattlerBase.prototype.tpRate = function() {		_Game_BattlerBase_tpRate.call(this);			if (($gameVariables.value(variableId) % 1 === 0) && 		$gameVariables.value(variableId)!= 0){			return this.tp / $gameVariables.value(variableId);		}else{			return this.tp / 100;		}	};	//TP Equation Alterations - GOOD	var _Game_Battler_initTp = Game_Battler.prototype.initTp;	Game_Battler.prototype.initTp = function() {		_Game_Battler_initTp.call(this);			this.setTp(eval(initialTPEqn));	};		//TP Charge Rate Alterations - GOOD	var _Game_Battler_chargeTpByDamage = Game_Battler.prototype.chargeTpByDamage;	Game_Battler.prototype.chargeTpByDamage = function(damageRate) {		if (eval(chargeTP)){			var value = Math.floor(50 * damageRate * this.tcr);			this.gainSilentTp(value);		} else {		}	};})();  
  6. Did you name the .js file TDW_TP_Changes.js?
  7. Yes I did!
  8. If it works, that's great! I'm surprised if(var) didn't work, but I suppose it must have something to do with the way parameters are managed. Beyond that, I imagine the consequences of using eval in this specific way will probably be minimal. Glad you got it working!