• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

New battle function prevents damage being dealt

  • 119
    Posts
    11
    Years
    • Seen Sep 1, 2023
    I was trying to implement a new stat for Pokémon which also affects their performance in battle. When a Pokémon uses a damage dealing attack the random number in the damage formula, which is actually a multiplier between 85 and 100 for the damage (which gets divided by 100 afterwards), is modified depending on the attacker's, and opponent's, value in the new stat. One increases the random number up to 20, while the other decreases the number up to 20. This is done by calling a function from the Pokémon class for each (attacker and opponent) inside the calculation which sets the random number.

    The problem I'm heaving right now is that with the added functionality, Pokémon don't take damage. It seems to skip the functions as if it doesn't have enough time to execute them. When the two calls aren't made everything functions as it should. When making the two calls elsewhere they return the correct values. And when replacing the two calls with possible numbers they could return, it also still works. Therefore it seems that nothing is wrong with the functions.

    For clarity, the code is placed below.

    Code:
    #PokeBatle_Move script, around line 823;
        if (options&NOWEIGHTING)==0
          [email protected](16)+opponent.randommod-attacker.randommod
          damage=(damage*random/100).floor
        end
    
    #Then in the PokeBattle_Pokemon script, where I placed the new function above def initialize
      def randommod
        mod = ((100+self.level*9)-@newstat)*20/(100+self.level*9)
        return mod
      end
    # "attr_accessor(:newstat)" is placed at the start of the class
    # "@newstat" is declared in def initialize, and can vary between 0 and (100+self.level*9)

    I have no clue where to look for the solution. I would really appreciate it if anyone could help me with this.
     
    What I tend to do when things like this happen is place a load of prints with different arguments after each line in order to check where my code is failing. For example:

    Code:
        print "1"
        if (options&NOWEIGHTING)==0
          print "2"
          [email protected](16)+opponent.randommod-attacker.randommod
          print "3"
          damage=(damage*random/100).floor
          print "4"
        end
    
      def randommod
        print "5"
        mod = ((100+self.level*9)-@newstat)*20/(100+self.level*9)
        print "6"
        return mod
        print "7"
      end

    Run something like that and see where the code stops executing.

    You could also use Ruby's built in trace function but that's fiddly with RMXP.
     
    I do that too, but only when I'm not sure where a problem occurs or when I want to know the value of something (I just print that value).

    Alternatively, set $INTERNAL=true to make debug messages show up during battle. This is your best bet for locating the error's source.

    Did you try using self.newstat instead of @newstat?
     
    Ok, apparently the problem was that the attacker and opponent aren't Pokémon, but Battlers. After setting $INTERNAL=true it gave an undefined method error. I was working under the assumption that both would be from the PokeBattle_Pokemon class.

    The problem seems to be fixed by adding .pokemon right after attacker and opponent.

    Thanks for the tips and pointing me in the right direction of solving it.
     
    Last edited:
    Back
    Top