MV - Need help fixing a small line of code

● ARCHIVED · READ-ONLY
Started by uwucutey 4 posts View original ↗
  1. I've been attempting to change the damage font size to 40 whenever damage critically hits as opposed to +4, so damage numbers would be bigger on critical hits. But I'm not sure how to place main.fontSize in this setupCriticalEffect bracket without causing the game to crash or to say this.fontsize doesn't exist. Either all the damage numbers ends up 40 size or +4 standard, or the game crashes, (this is from sprites.js) I'm not sure what line to put here. Thank you.
  2. As you can see, setupCriticalEffect is called after makeDigits, which is where the font size is referenced. You will either need to acknowledge the critical hit earlier and use that to alter the font size (recommended), or redraw all critical hit popups in the larger font size.

    This might work:
    Plugin code suggestion
    JavaScript:
    (() => {
    'use strict';
      let crit = false;  // internal flag, passes status between independent methods
    
      (alias  => {
        Sprite_Damage.prototype.setup = function(target) {
          crit = target.result().critical;  // update crit flag
          alias.apply(this, arguments);  // default setup
        };
      })(Sprite_Damage.prototype.setup);
    
      (alias => {
        Sprite_Damage.prototype.fontSize = function() {
          if (crit) return 40;  // font size 40 if crit
          return alias.apply(this, arguments);  // otherwise default size
        };
      })(Sprite_Damage.prototype.fontSize);
    
    })();
    This is intended for use as a plugin:
    1. Copy+paste into a text editor (e.g. Notepad)
    2. Save As > File Type: All Files, Filename: whatever.js
    3. Import as a plugin through the Plugin Manager
    4. Save your project to apply Plugin Manager changes
    5. Test!
    It's typically recommended to write code changes as plugins rather than edit the core scripts: core script changes are harder to track and will be lost if/when you update your project's core script version.

    Note on code style
    The following snippets are all essentially identical:
    JavaScript:
    (function() {
      let cake = 'tasty';
      alert(cake);
    })();
    JavaScript:
    (() => {
      let cake = 'tasty';
      alert(cake);
    })();
    JavaScript:
    (cake => {
      alert(cake);
    })('tasty');
    This is called an IIFE, more info here:
  3. you explained it really well and the script works great, thanks for the script, link, and easy explanation. :)
  4. [move]Javascript/Plugin Support[/move]