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.
MV Need help fixing a small line of code
Javascript/Plugin SupportAs you can see,
This might work:
This is intended for use as a plugin:
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:
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);
})();
- Copy+paste into a text editor (e.g. Notepad)
- Save As > File Type: All Files, Filename: whatever.js
- Import as a plugin through the Plugin Manager
- Save your project to apply Plugin Manager changes
- Test!
The following snippets are all essentially identical:
This is called an IIFE, more info here:
developer.mozilla.org
JavaScript:
(function() {
let cake = 'tasty';
alert(cake);
})();
JavaScript:
(() => {
let cake = 'tasty';
alert(cake);
})();
JavaScript:
(cake => {
alert(cake);
})('tasty');
IIFE - Glossary | MDN
An IIFE (Immediately Invoked Function Expression) is an idiom in which a JavaScript function runs as soon as it is defined. It is also known as a self-executing anonymous function. The name IIFE is promoted by Ben Alman in his blog.
you explained it really well and the script works great, thanks for the script, link, and easy explanation. 🙂
Moved to: Javascript/Plugin Support
Original thread: https://forums.rpgmakerweb.com/threads/need-help-fixing-a-small-line-of-code.135929/