Default experience calculation in RPGM VXA...

Hi,

i am searching for a way to modify the exp curves (in my case the curves are defined using the default formular) dynamically ingame, so e.g. i want to be able to move the curve vertically by using a game_variable.
rpgmakervxace_expcurve.png


i also read the following to find out that the inbuilt method which contains the exp curve calculation is encapsulated in Game_Actors class which can be found in the Script Editor: https://forums.rpgmakerweb.com/index.php?threads/himes-custom-exp-curves.80340/post-748097
but for some reason if i modify Game_Actor.exp_for_level(level) the game crashes on some random point later, so what i did was adding a game_variable (containing a number) to the result of self.class.exp_for_level(level).
no_round_for_complex_crash.png


How can i actually modify the inbuilt methods ?
rpg_class_exp_for_level.png

i only wanna alter the curve by adding an integer from an game_variable to it.

EDIT:
i found out why it crashes, see answers below.
@Regda Hi and welcome. I've split your question into it's own post. We prefer members start a new thread for their own questions, particularly in old threads. If any relevant information has been left out, please go back and edit your original post to include that. Thanks.
Don't know what you've exactly changed from the default or where and how you at least plan to implement the variable to take effect inside it, so it's not that easy to help you with the formula.

But according to the error some part is (I assume accidentally) generating "0.0i" which is not a regular number, so the interpreter creates an object-instance of Complex-class there (still based on Numeric which is needed as parent class to use #round in a calculation, though Complex doesn't support it).

~炬燵あ
or in other words, most likely you have a type in your modified formula, and we need to see what you tried to enter there instead of the original default values.
the modified formular was the following:
Ruby:
# $game_variables[127] = 22
# class Game_Actor
def exp_for_level(level)
  self.class.exp_for_level(level) + $game_variables[127]
end

the game actually crashed because at the end 0 (or smaller) has been passed to Change EXP (increase), so i solved the crash by just not calling it if the argument is 0 or below.

My main question is still there, how can i overwrite the inbuilt method exp_for_level of this RPG::Class class?
(Ofc. i could change the Game_Actor.exp_for_level(level) method but then i have to make sure that everywhere else the exp_for_level of Game_Actor is used instead of the inbuilt exp_for_level)
the modified formular was the following:
Ruby:
# $game_variables[127] = 22
# class Game_Actor
def exp_for_level(level)
  self.class.exp_for_level(level) + $game_variables[127]
end

the game actually crashed because at the end 0 (or smaller) has been passed to Change EXP (increase), so i solved the crash by just not calling it if the argument is 0 or below.

My main question is still there, how can i overwrite the inbuilt method exp_for_level of this RPG::Class class?
(Ofc. i could change the Game_Actor.exp_for_level(level) method but then i have to make sure that everywhere else the exp_for_level of Game_Actor is used instead of the inbuilt exp_for_level)
JavaScript:
class RPG::Class < RPG::BaseItem
  alias :tlb_exp_for_level :exp_for_level
  def exp_for_level(level)
    return tlb_exp_for_level(level) + $game_variables[127]
  end
end
i assume i have to put this code at the very top of the script editor ? (just to go sure)

This time the game crashes at Change EXP (increase) if the value passed to it is less then $game_variables[127].

So e.g. if i hardcode the variable to 20:
Ruby:
class RPG::Class < RPG::BaseItem
  alias :tlb_exp_for_level :exp_for_level
  def exp_for_level(level)
    return tlb_exp_for_level(level) + 20
  end
end
The first time Change EXP (increase) is called with a value lower then 20 it crashes:
changeexp.png

(i also unticked "Show Level Up Message" to get sure it's not because of printing something)

EDIT:
ok, on an clean project it seems like to work... looks like the problem lies on my side (or better in one of all these scripts im using... ). 😅
What bothers me atm is that on the clean project it shows "Current Exp: 20; To Next Level: 90", where on my actual project it shows "Current Exp: 0; To Next Level: 110"...
so based on the code above i was expecting the result on my actual project, maybe i still missunderstand how exp is calculated.
(the affected hero uses [50, 40, 50, 50] as Exp Curve so Lvl 1 should start with 90exp to Lvl 2)
i assume i have to put this code at the very top of the script editor ? (just to go sure)
no, usually all scripts should be added to the materials section of the script editor.
there are very few exceptions to that rule.
Not sure if this is the issue, but the method determines the breakpoint for total exp needed to reach a certain level, not the increase from one level to the next.
You can get a complex result if you take a negative number to the power of a non-integer (often taking the square root).
no, usually all scripts should be added to the materials section of the script editor.
there are very few exceptions to that rule.
Ok, i moved the Code to the bottom of the materials section.

Not sure if this is the issue, but the method determines the breakpoint for total exp needed to reach a certain level, not the increase from one level to the next.
You mean exp_for_level? Hm then i missunderstood the method (see spoiler below), the only thing that comes to my mind atm is multiplying it with the actual level befor adding.
Spoiler
As i undstood it, the idea is to have a pool of exp which then is divided into 100 Levels where the divisions are defined by the exp curve... so i was thinking i could just add something on top of the results from exp_for_level to move the curve upwards (which would be always e.g. 20 more whatever level is given) :|

I tested it again with my actual Project but this time with a new savegame, could it be that savegames interfere with it if so how do i update the loaded values?
With an old save i get "Current Exp: 0; To Next Level: 110" and the game crashes if the exp is below the value that has been added to exp_for_level.
With an new save i get "Current Exp: 20; To Next Level: 90" and the game doesn't crash.
(im not sure yet if this behavior comes from an script or not)
I tested it again with my actual Project but this time with a new savegame, could it be that savegames interfere with it if so how do i update the loaded values?
With an old save i get "Current Exp: 0; To Next Level: 110" and the game crashes if the exp is below the value that has been added to exp_for_level.
With an new save i get "Current Exp: 20; To Next Level: 90" and the game doesn't crash.
(im not sure yet if this behavior comes from an script or not)
100%
Any data that is saved in the save game (actor data and more) will cause problems when you change code that reads and uses the save game data.
I can only repeat my question. :LZSsad:
If an Savegame is loaded, which data (exactly) do i have to adjust?
(so how do i find out what is affected from changing exp_for_level so that i can write update routines for it? )
The savestate saves both the actors level and exp separately. If both are no longer consistent, you'd have to make a choice:

If you want to keep an actors level intact, you could use something like
actor.change_exp(actor.current_level_exp) if actor.exp < actor.current_level_exp
actor.change_exp(actor.next_level_exp - 1) if actor.exp >= actor.next_level_exp
to update their exp to match it.

If you want to keep the exp intact, you could use
actor.change_exp(actor.exp)
to update their level.

That said, your error seems to originate from the fact that the original exp formula was not designed to work for levels below 1 (and you only reach level 1 at 20 exp right now).

Original thread: https://forums.rpgmakerweb.com/threads/default-experience-calculation-in-rpgm-vxa.150002/