I need feedback for a very simple plugin I made!

● ARCHIVED · READ-ONLY
Started by Ras101 7 posts View original ↗
  1. Hi everyone. I'm looking for some feedback on this very simple plugin I made that changes the critical hit multiplier. I created this plugin so I can practice coding in Javascript for MV and also to practice my Javascripting in general. I'm still a noob in Javascript, which is why I'm asking for some feedback!

    The plugin works perfectly, I just want to know if there are things I can improve/adjust, any good coding practices I should follow if I haven't etc.

    Without further ado, here is the code!

    Code:
    //=============================================================================// ModifyCriticalHit.js//=============================================================================/*: * @plugindesc v1.00 simple plugin to change critical hit multiplier * @author PhantomStream * * @help A simple plugin to change the critical hit multiplier. The default * value of 3 is a little bit too high for my purposes, so that's why I created * this plugin! *  * @param Critical Multiplier * @desc The value that damage is multiplied with for critical hits. * RPG Maker MV's default multiplier is 3. * @default 3*///=============================================================================// Changelog//=============================================================================/* *	v1.00 (26/10/2015) - Started and finished plugin!*///=============================================================================// Parameters//=============================================================================(function() {var parameters = PluginManager.parameters('ModifyCriticalHit');var critMultiplier = parameters['Critical Multiplier'];//=============================================================================// Actual code//=============================================================================var _Game_Action_criticalMultiplier = Game_Action.prototype.applyCritical;Game_Action.prototype.applyCritical = function(damage) {    return damage * critMultiplier;};})(); //can't touch this//=============================================================================// End of code!//=============================================================================
  2. You should make sure that the parameter you receive is a number and provide a fallback:

    var critMultiplier = parseFloat(parameters['Critical Multiplier']) || 0;Note, that i did a fallback to 0, not 3. This is because 0 is considered falsy and if someone where to provide "0" as a parameter, if would automatically take the fallback value. A cleaner, but longer approach would be storing the "parseFloat(...)" first and than ask for NaN like this:
    Code:
    var critMultiplier = parseFloat(parameters['Critical Multiplier']);!isNaN(critMultiplier) || (critMultiplier = 3);
    NaN is the value you get back when parseFloat() or parseInt() can't find a valid number./edit: Don't make the same error i just did and try to compare like "critMultiplier !== NaN". 2 NaN values are never the same.

    Also, it's generally good practice to alias functions before overwriting them, but since you never call the alias you could as well delete this line:

    Code:
    var _Game_Action_criticalMultiplier = Game_Action.prototype.applyCritical;
    Remember, that your script is probably incompatible with other scripts that overwrite that function in some way.
  3. Ah, okay! Thank you for the input.

    So, is there some way I can calculate the critical damage differently without overwriting the original applyCritical function?
  4. PhantomStream said:
    Hi everyone. I'm looking for some feedback on this very simple plugin I made that changes the critical hit multiplier. I created this plugin so I can practice coding in Javascript for MV and also to practice my Javascripting in general. I'm still a noob in Javascript, which is why I'm asking for some feedback!

    The plugin works perfectly, I just want to know if there are things I can improve/adjust, any good coding practices I should follow if I haven't etc.

    Without further ado, here is the code!

    //=============================================================================// ModifyCriticalHit.js//=============================================================================/*: * @plugindesc v1.00 simple plugin to change critical hit multiplier * @author PhantomStream * * @help A simple plugin to change the critical hit multiplier. The default * value of 3 is a little bit too high for my purposes, so that's why I created * this plugin! * * @param Critical Multiplier * @desc The value that damage is multiplied with for critical hits. * RPG Maker MV's default multiplier is 3. * @default 3*///=============================================================================// Changelog//=============================================================================/* * v1.00 (26/10/2015) - Started and finished plugin!*///=============================================================================// Parameters//=============================================================================(function() { // Indent your code})(); //can't touch this//=============================================================================// End of code!//=============================================================================
    I made one small change, if you look at the quoted post, youll see I made a comment, indent your code
  5. PhantomStream said:
    So, is there some way I can calculate the critical damage differently without overwriting the original applyCritical function?
    Well, I'm new to this too, but it seems to me that if you made the second multiplier *in addition to* the normal *3, you wouldn't need to replace it. So for instance if you wanted 1.5x crits, your added multiplier would be .5. Then just alias the original function and add yours after before (EDIT: add yours before rather than after you call the original code, since it immediately returns a value). If you are worried about confusion to the user, then just perform the reverse adjustment on their data. So if they wanted a 6x crit multiplier (and what a terrifying game that would be), you could take their number and divide it by 3 to get your second multiplier. It's only marginally more work for you and doesn't run the risk of confusing the game maker.
  6. But in exchange you confuse the user.


    Id say in this case, where you actually want to replace the original value, instead of extending it, it's totally viable to overwrite the function. Your plugin will need to be somewhere at the top of the plugin list, so you won't overwrite the addition to applyCritical() that other plugins might have done, but have them work with your function, instead.
  7. Thank you everyone for your input! I think for now I'll leave the plugin as is, overwriting the original function, but in the future I may have to find a workaround in case it will conflict with other plugins.