Need help adding usable attributes to RPG::State

● ARCHIVED · READ-ONLY
Started by Wavelength 4 posts View original ↗
  1. I've modified and defined classes before, but I've never worked with the "RPG::" Classes themselves before, and I think I'm doing something wrong here because I can't figure out why else I'd be getting these strange errors.

    I wanted to add attributes to the RPG::State class, so, in its simplest form, this is how I set it up:

    class RPG::State < RPG::BaseItem   #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  alias :scaling_initialize :initialize  def initialize    scaling_initialize        @dur_scale_type = 3    @dur_scale_form = ""      end   #--------------------------------------------------------------------------  # * Public Instance Variables  #--------------------------------------------------------------------------  attr_accessor :dur_scale_type  attr_accessor :dur_scale_formendNow, I want to use those two new attributes when adding a State to a battler in battle.  So I went to Game_Battler and overwrote the reset_state_counts method as such:

    class Game_Battler < Game_BattlerBase  #--------------------------------------------------------------------------  # * Reset State Counts (Turns and Steps)  #      Overwrite Method!  Performs original state-count set, then new stuff.  #--------------------------------------------------------------------------  def reset_state_counts(state_id, user, target, item)    # Old Code is here!    state = $data_states[state_id]    variance = 1 + [state.max_turns - state.min_turns, 0].max    @state_turns[state_id] = state.min_turns + rand(variance)    @state_steps[state_id] = state.steps_to_remove    # New Code starts here!    if state.dur_scale_type > 0 # THIS IS THE ERROR LINE!!!      if state.auto_removal_timing > 0        if @state_turns != nil          case state.dur_scale_type          when 1            @state_turns[state_id] += refine_scaling_value(state.dur_scale_form, user, target)          when 3            @state_turns[state_id] = refine_scaling_value(state.dur_scale_form, user, target)        end      end    end  end endWhen the game starts, I get an error because of the line "if state.dur_scale_type > 0".

    The error message reads:

    Script 'Scaling_Utility' line 93: NoMethodError occurred.

    undefined method `>' for nil:NilClass

    When I change the line to read "if state.dur_scale_type != 0" instead of "if state.dur_scale_type > 0", the game starts okay, but the functionality I've built with the script seems to be ignored.

    Together with some other trial and error that I did, these problems make me think that for some reason, dur_scale_type is being treated as a variable, but not as an integer variable.  I can't figure out why this would be the case.

    Notes: I added the extra arguments into methods that call the reset_state_counts method, and I think I got them all.  I defined a refine_scaling_value method inside the Game_Battler class.  I removed code that I don't believe is relevant, to make the code block less absurdly long as you try to help me out with this.  If you think you need to see more, I'll post the entire script, as it stands now.

    If anyone can help me solve this problem, you'll make my day!  THANK YOU.
  2. Database objects are not initialized. They are simply loaded from pre-generated database files


    Therefore whatever code you put inside `initialize` won't be executed.


    This only applies to the objects that you created through the editor.


    You need to explicitly initialize those values yourself.


    This is why I always lazy-load my database objects.


    Some scripters explicitly iterate over them during game startup to do things like load note-tags to populate those values.
  3. You're a legend and a scholar, Hime!  Thanks so much for your advice; it got me on the right track and it looks like the base functionality for my script is working now.  I wish there were a way to add ten Likes to your post. :)

    With the fact that I can't modify the "initialize" method in mind, I followed the same general idea of this "set max values" script - aliasing the load_normal_database and load_battle_test_database methods to iterate through each state and run a new "init_scaling" method that I defined inside RPG::State.  Is this what you were saying some scripters do at game startup?  Is it significantly worse than lazy-loading in any way?
  4. Your values are explicitly set by calling the appropriate loading methods at startup.


    This means that as long as the load database methods are called, everything is great.


    But are there cases where data does not exist yet in the database when you run those methods?