- 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.
I have no clue where to look for the solution. I would really appreciate it if anyone could help me with this.
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.