Damage Formula causing MANY errors

salohcin714

Villager
Member
Joined
Apr 4, 2017
Messages
9
Reaction score
0
First Language
English
Primarily Uses
RMMV
So, I've been trying to set up my damage formula similar to that of Final Fantasy 6 using Yanfly's Damage Core and keep getting tons of errors whenever an attack is used:

Code:
SyntaxError: Illegal return statement {stack: "SyntaxError: Illegal return statement↵    at Game_…ject1/js/plugins/YEP_BattleEngineCore.js:1870:10)", message: "Illegal return statement"}message: "Illegal return statement"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__:
ErrorYEP_RowFormation.js:2438 Yanfly.Util.displayError
YEP_DamageCore.js:1231 Game_Action.makeDamageValue
YEP_X_SelectionControl.js:1051 Game_Action.makeDamageValue
rpg_objects.js:1656 Game_Action.apply
YEP_BattleEngineCore.js:3273 Game_Action.apply
YEP_BattleAICore.js:780 Game_Action.apply
YEP_BuffsStatesCore.js:1676 Game_Action.apply
YEP_SkillCore.js:1041 Game_Action.apply
YEP_RowFormation.js:1405 Game_Action.apply
rpg_managers.js:2181 BattleManager.invokeNormalAction
YEP_BattleEngineCore.js:1870 BattleManager.invokeAction
YEP_BattleEngineCore.js:2482 (anonymous function)
YEP_BattleEngineCore.js:2479 BattleManager.actionActionEffect
YEP_BattleEngineCore.js:2075 BattleManager.processActionSequence
YEP_X_ActSeqPack1.js:870 BattleManager.processActionSequence
YEP_X_ActSeqPack2.js:575 BattleManager.processActionSequence
YEP_X_ActSeqPack3.js:393 BattleManager.processActionSequence
YED_SideviewBattler.js:498 BattleManager.processActionSequence
YEP_X_BattleSysATB.js:1305 BattleManager.processActionSequence
YEP_X_CounterControl.js:1394 BattleManager.processActionSequence
YEP_DamageCore.js:890 BattleManager.processActionSequence
YEP_ElementCore.js:424 BattleManager.processActionSequence
YEP_BattleEngineCore.js:2057 BattleManager.processActionSequenceCheck
YEP_BattleEngineCore.js:2013 BattleManager.updateActionTargetList
YEP_BattleEngineCore.js:1688 BattleManager.update
YEP_X_BattleSysATB.js:971 BattleManager.update
rpg_scenes.js:2050 Scene_Battle.updateBattleProcess
rpg_scenes.js:2042 Scene_Battle.update
YEP_BattleEngineCore.js:4308 Scene_Battle.update
YEP_RowFormation.js:2184 Scene_Battle.update
rpg_managers.js:1673 SceneManager.updateScene
This is what I currently have the damage formula set up as:
Code:
var power = this.evalDamageFormula(target);
var damage = 0;
var value = 0
//Base Formula for Magical Skills
if (this.isMagical()){
    damage = power * 4 + Math.int(user.level * user.mat * power / 32);
}
//Base Formula for Physical Skills
if (this.isPhysical()){
    damage = power + Math.int((Math.pow(user.level, 2) * (power * user.atk)) / 256) * 3 / 2;
   //Check if user in back row
   if (battler.row() = 2) {
        damage = damage / 2;
    }
   //Check if critical
    if (critical) {
        damage = damage * 2;
    }
}
//Add variance
damage = Math.int(damage * Math.int((224 + Math.int(31 * Math.random())/256)));
//Magic Defense Reduction
if (this.isMagical()) {
    damage = Math.int(damage * Math.int(255 - target.mdf) / 256);
    //Check if target has Shell state
    if (target.isStateAffected(50)) {
        damage = Math.int(damage * 170 / 256);
    }
}
//Defense Reduction
if (this.isPhysical()) {
    damage = Math.int(damage * Math.int(255 - target.def) / 256);
    //Check if Target has Protect state
    if (target.isStateAffected(50)) {
        damage = Math.int(damage * 170 / 256);
    }
}
//Check if target is defending
if (target.isStateAffected(9)) {
    damage = Math.int(damage / 2);
}
//Element Multipler
damage = Math.int(damage * this.calcElementRate(target));
value = damage
return value
I thought the issue was being caused by battler.rows() but after removing that section, I'm still getting errors.

Any help is appreciated
 
Last edited:

Naveed

Veteran
Veteran
Joined
Nov 2, 2013
Messages
314
Reaction score
146
First Language
English
Primarily Uses
RMMV
Firstly, you'll need to state which plugin you're using to change the damage formula, and how you're setting it up (as in where are you inputting the code). Is it for a specific skill or the general damage flow (using the parameters in Yanfly's damage core plugin)?
 

salohcin714

Villager
Member
Joined
Apr 4, 2017
Messages
9
Reaction score
0
First Language
English
Primarily Uses
RMMV
Firstly, you'll need to state which plugin you're using to change the damage formula, and how you're setting it up (as in where are you inputting the code). Is it for a specific skill or the general damage flow (using the parameters in Yanfly's damage core plugin)?
I'm using Yanfly's Damage Core. This the general damage flow for all skills. The damage formulas in the database will only contain the attack power of the skill which is set to the power variable in the damage flow.

Edit: I added comments into the code in my original post to help show what each step is for
 
Last edited:

Naveed

Veteran
Veteran
Joined
Nov 2, 2013
Messages
314
Reaction score
146
First Language
English
Primarily Uses
RMMV
Well, your code was mostly correct, but the main issue was using Math.int() whereas it should be either Math.floor() or Math.round() (depending on what you were trying to do). Also, battler.row() is not the appropriate syntax as the 'battler' was meant to be replaced by the appropriate battler, which I believe you meant to be the user. Speaking of which, 'user' in the code is undefined as you did not define it, so there should be a line near the top that says var user = this.subject().

I looked through the code and understood what you were trying to do. Here's what I came up with after some polishing, but didn't test it yet. Let me know if errors still occur.

Code:
var power = baseDamage;
var damage = 0;
var value = 0;
var user = this.subject();
if (this.isMagical()){
    damage = power * 4 + Math.floor(user.level * user.mat * power / 32);
}
if (this.isPhysical()){
    damage = power + Math.floor((Math.pow(user.level, 2) * (power * user.atk)) / 256) * 1.5;
    if (user.row() === 2) {
        damage /= 2;
    }
    if (critical) {
        damage *= 2;
    }
}
damage = Math.floor(damage * Math.floor((224 + Math.floor(31 * Math.random())/256)));
if (this.isMagical()) {
    damage = Math.floor(damage * Math.floor(255 - target.mdf) / 256);
    if (target.isStateAffected(50)) {
        damage = Math.floor(damage * 170 / 256);
    }
}
if (this.isPhysical()) {
    damage = Math.floor(damage * Math.floor(255 - target.def) / 256);
    if (target.isStateAffected(50)) {
        damage = Math.floor(damage * 170 / 256);
    }
}
if (target.isStateAffected(9)) {
    damage = Math.floor(damage / 2);
}
damage = Math.floor(damage * this.calcElementRate(target));
value = damage;
 

salohcin714

Villager
Member
Joined
Apr 4, 2017
Messages
9
Reaction score
0
First Language
English
Primarily Uses
RMMV
Well, your code was mostly correct, but the main issue was using Math.int() whereas it should be either Math.floor() or Math.round() (depending on what you were trying to do). Also, battler.row() is not the appropriate syntax as the 'battler' was meant to be replaced by the appropriate battler, which I believe you meant to be the user. Speaking of which, 'user' in the code is undefined as you did not define it, so there should be a line near the top that says var user = this.subject().

I looked through the code and understood what you were trying to do. Here's what I came up with after some polishing, but didn't test it yet. Let me know if errors still occur.

Code:
var power = baseDamage;
var damage = 0;
var value = 0;
var user = this.subject();
if (this.isMagical()){
    damage = power * 4 + Math.floor(user.level * user.mat * power / 32);
}
if (this.isPhysical()){
    damage = power + Math.floor((Math.pow(user.level, 2) * (power * user.atk)) / 256) * 1.5;
    if (user.row() === 2) {
        damage /= 2;
    }
    if (critical) {
        damage *= 2;
    }
}
damage = Math.floor(damage * Math.floor((224 + Math.floor(31 * Math.random())/256)));
if (this.isMagical()) {
    damage = Math.floor(damage * Math.floor(255 - target.mdf) / 256);
    if (target.isStateAffected(50)) {
        damage = Math.floor(damage * 170 / 256);
    }
}
if (this.isPhysical()) {
    damage = Math.floor(damage * Math.floor(255 - target.def) / 256);
    if (target.isStateAffected(50)) {
        damage = Math.floor(damage * 170 / 256);
    }
}
if (target.isStateAffected(9)) {
    damage = Math.floor(damage / 2);
}
damage = Math.floor(damage * this.calcElementRate(target));
value = damage;
No longer getting errors! Though I am getting some crazy high damage values. I'll go through again and make sure that everything's copied correctly.

Thank you for all of your help! This isn't the first time you've solved a problem for me (and I'm sure not the last). I'm surprised there weren't more errors in my code as I've been just learning it as I've been working on my project for the past few months.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,047
Members
137,569
Latest member
Shtelsky
Top