Overriding a method in Game_BattlerBase isn't working for me

GolfHacker

Veteran
Veteran
Joined
Feb 15, 2015
Messages
477
Reaction score
682
First Language
English
Primarily Uses
RMVXA
I'm working with Yami's Battle Symphony and Yanfly's Battle Engine Ace, and I ran into a small problem.

Before you groan and skip this message because you think it's too involved:

1) My question really doesn't have a lot to do with Yami's or Yanfly's scripts, it's more of a general scripting question.

2) I know what the problem is, and I know what needs to be done to fix it. (I'm a programmer in real life, and I've been tinkering with scripting.) I'm just not sure why my "patch" is not working. It's probably something really simple I've overlooked. Or perhaps, I'm misunderstanding something about RGSS3.

First, I need to give some specifics to help you understand the problem I'm trying to solve.

Using Yami's tags (see below) in the skill notes box, I want my skill to calculate the miss/evade flags, and only show the "hit" animation on the target battler if a hit does in fact occur. Yami's tags allow me to separate the miss/evade and damage calculations, so that's good. When the miss/evade evaluation is performed, I can apply a hit state, and then I can determine if a hit actually occurs or not. It all works, except a weird "NULL" popup message is displayed right before the actual damage is shown. Here are my symphony tags on my skill:

<setup action>move user: forward, waitstance: user, forwardmove user: target, foot, wait</setup action><target action>animation 114: targetstance: user, attackwait: 15skill effect: effect, calcif target.state?(48)stance: target, struckanimation 23: target, waitskill effect: dmgremove state 48: targetendwait: 10</target action><finish action>stance: user, retreatmove user: origin, waitstance: user, idle</finish action>So the "skill effect: effect, calc" line causes a NULL popup to appear, even though no damage has been calculated yet. I traced the NULL popup to Yanfly's Battle Engine Ace script. In the Game_BattlerBase class, he defines a make_miss_popups method that has this code:
 

  def make_miss_popups(user, item)    return if dead?    if @result.missed      text = YEA::BATTLE::pOPUP_SETTINGS[:missed]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.evaded      text = YEA::BATTLE::pOPUP_SETTINGS[:evaded]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.hit? && !@result.success      text = YEA::BATTLE::pOPUP_SETTINGS[:failed]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.hit? && item.damage.to_hp?      if @result.hp_damage == 0 && @result.hp_damage == 0        text = YEA::BATTLE::pOPUP_SETTINGS[:nulled]        rules = "DEFAULT"        create_popup(text, rules)      end    endendThe problem with this code is the final if block. In the case of Yami's Battle Symphony, this method is called when the miss/evade flags are computed, and no damage has been calculated yet. So result.hp_damage is 0, which causes it to display the popup. This method needs another check to see if damage has in fact been calculated, and if not, skip the popup. (a case that probably only occurs with Yami's Battle Symphony)

Fortunately, Yami's script adds this very thing (a dmg attribute) to the Game_ActionResult class.

So, I thought I would write a simple patch to override Yanfly's make_miss_popups method and add this check. The problem is, it isn't working. Yanfly's script still uses the original code. It doesn't appear to be calling my new method. I thought by redefining this method, Yanfly's script would call my new method instead of the original one. What am I doing wrong in my patch? Here's the code for my patch script:

class Game_BattlerBase   # Override this method that Yanfly added. I keep most of the code intact, but add the extra check at the end.  def make_miss_popups(user, item)    return if dead?    if @result.missed      text = YEA::BATTLE::pOPUP_SETTINGS[:missed]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.evaded      text = YEA::BATTLE::pOPUP_SETTINGS[:evaded]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.hit? && !@result.success      text = YEA::BATTLE::pOPUP_SETTINGS[:failed]      rules = "DEFAULT"      create_popup(text, rules)    end    # This adds the result.dmg? check to see if damage has been    # calculated. If it hasn't, it skips the NULL popup.    if @result.hit? && item.damage.to_hp? && @result.dmg?      if @result.hp_damage == 0 && @result.hp_damage == 0        text = YEA::BATTLE::pOPUP_SETTINGS[:nulled]        rules = "DEFAULT"        create_popup(text, rules)      end    end  end end # Game_BattlerBaseThe order of scripts in my project is:

Yanfly's Battle Engine Ace

Yami's Battle Symphony

Yami Skill Effect Tags

Yami Holder Battler Add-on

My patch

Here are the links to the scripts I'm using:

https://yanflychannel.wordpress.com/rmvxa/battle-scripts/ace-battle-engine/

https://github.com/suppayami/rmvxa-collection/blob/master/battle-symphony/battle-symphony-116c.rb

https://github.com/suppayami/rmvxa-collection/tree/master/battle-symphony/add-on

Anyone know why it is still using the original code in Yanfly's script instead of my overridden method?
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
According to your post, yanfly made it in Game_Battler but your new mthod was in Game_BattlerBase... Since Game_Battler is a child of Game_BattlerBase, the overwrite you made in Base doesnt work on Game_Battler and its child classes as the method also exists in Game_Battler..

Methods in child classes overwrite those in the parent class.
 
Last edited by a moderator:

GolfHacker

Veteran
Veteran
Joined
Feb 15, 2015
Messages
477
Reaction score
682
First Language
English
Primarily Uses
RMVXA
Oops - that was a typo on my part. Yanfly did put it in Game_BattlerBase.
 
Last edited by a moderator:

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Have you checked to see if Battle Symphony overrode the method that calls this method? If it did, it might have its own processing and be totally skipping this code for that reason.
 

GolfHacker

Veteran
Veteran
Joined
Feb 15, 2015
Messages
477
Reaction score
682
First Language
English
Primarily Uses
RMVXA
Ah, good call bgillisp! Yami's script does override it in GameBattler!

Let me see if I can figure out how to override that. I'm assuming I need to override it in both the base class and GameBattler...

Edit: ok, I'm not sure this is the most efficient way to do this, but it works! But I'm open to suggestions, if there's a better way to do it than by duplicating the same code in both places. I tried aliasing the method in my Game_Battler, but it didn't call the overridden method in my Game_BattlerBase - it called the original one in Yanfly's. So duplicating the code was the only way I could see to get it to work.

Code:
#==============================================================================# Game_BattlerBase#==============================================================================class Game_BattlerBase  def make_miss_popups(user, item)    return if dead?    if @result.missed      text = YEA::BATTLE::POPUP_SETTINGS[:missed]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.evaded      text = YEA::BATTLE::POPUP_SETTINGS[:evaded]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.hit? && !@result.success      text = YEA::BATTLE::POPUP_SETTINGS[:failed]      rules = "DEFAULT"      create_popup(text, rules)    end    # This adds the result.dmg? check to see if damage has been    # calculated. If it hasn't, it skips the NULL popup.    if @result.hit? && item.damage.to_hp? && @result.dmg?      if @result.hp_damage == 0 && @result.hp_damage == 0        text = YEA::BATTLE::POPUP_SETTINGS[:nulled]        rules = "DEFAULT"        create_popup(text, rules)      end    end  end end # Game_BattlerBase#==============================================================================# Game_Battler# Yami's script overrides this method in the derived Game_Battler class.# So I need to do the same thing there.#==============================================================================class Game_Battler < Game_BattlerBase  if $imported["YEA-BattleEngine"]  def make_miss_popups(user, item)    # This is from Yami's overridden method.    @result.restore_damage unless @result.effect?    # At this point, Yami's script calls the base class. So I need to    # do my custom version here.    return if dead?    if @result.missed      text = YEA::BATTLE::POPUP_SETTINGS[:missed]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.evaded      text = YEA::BATTLE::POPUP_SETTINGS[:evaded]      rules = "DEFAULT"      create_popup(text, rules)    end    if @result.hit? && !@result.success      text = YEA::BATTLE::POPUP_SETTINGS[:failed]      rules = "DEFAULT"      create_popup(text, rules)    end    # This adds the result.dmg? check to see if damage has been    # calculated. If it hasn't, it skips the NULL popup.    if @result.hit? && item.damage.to_hp? && @result.dmg?      if @result.hp_damage == 0 && @result.hp_damage == 0        text = YEA::BATTLE::POPUP_SETTINGS[:nulled]        rules = "DEFAULT"        create_popup(text, rules)      end    end        # This is from Yami's overridden method.    unless @result.effect?      @result.store_damage      @result.clear_damage_values    end  end  endend
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Just override it on Game_Battler... That is the one used as a parent by enemies and actors anyway...
 

GolfHacker

Veteran
Veteran
Joined
Feb 15, 2015
Messages
477
Reaction score
682
First Language
English
Primarily Uses
RMVXA
Oh, ok! I wasn't sure how many things derived from Game_BattlerBase. Thanks!
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
You could do a ctrl shift F to search for the term Game_BattlerBase to have a list of scripts that use it. :)
 

GolfHacker

Veteran
Veteran
Joined
Feb 15, 2015
Messages
477
Reaction score
682
First Language
English
Primarily Uses
RMVXA
Now THAT is handy to know! Thanks for that awesome tip!
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Just to clarify, it will actually list all instances of the term that you searched, including on which script and line number it appears.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

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'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,019
Members
137,564
Latest member
McFinnaPants
Top