State Add/Remove Commands

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Shaz, Sep 30, 2013.

  1. Shaz

    Shaz Veteran Veteran

    Messages:
    37,710
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Yes, that is what I mean :p


    edit: in that case, it probably won't make a difference, because it's MV/Javascript that requires this. Ace will work without self.

    @Ninjakillzu can you confirm that you have done what I requested in my first response to you, by putting p $1 on that line and checking the output when the command is run? You didn't actually say that's what you did that led you to add_param.
     
    Last edited: Jul 2, 2019
    #81
  2. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    Sorry if I didn't say I did that. I did do it though. The reason it led me to add_param is that it would show up a ton in the console when it should only show up once, like it somehow was repeating itself over and over, and that's what lead to the crash. I tried it with self. but that didn't fix it.

     
    #82
  3. Shaz

    Shaz Veteran Veteran

    Messages:
    37,710
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    And did you do the other thing I requested, which was to put the commands into a script call in a regular event, and separate them from my script? You would need to have an object for this - so $game_actors[id].add_param(6, 6) or $game_actors[id].add_param(6, -6)?

    Do that inside a script call and not through the state add/remove commands script, to see if it's even related to my script.

    I also asked a number of other questions in my first reply, which you haven't answered.
     
    #83
  4. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    I just tested the script call in two separate events, one for increasing the parameters, and one for decreasing the parameters. Both worked without issues.

    As for the other questions, I did look through the thread earlier, and found nothing similar. I also did add p $1 before the eval($1) line. I didn't install the script twice or in the same slot. The crash only happens on enemies when any state is removed (with onremove) that has the add_param command part. As for looping, none of my states add or remove each other, so I don't know if it's possible otherwise.
     
    #84
  5. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,371
    Likes Received:
    4,942
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    I still feel like this is unfair that the error pointed out to this script while it does exactly nothing.
    For a "foolproof", try to change your add_param to literally like this
    Code:
    onremove: @param_plus[param_id] += value;refresh
    
    Of course, change the param_id and value to what you need. See if it still yields stack error
     
    #85
  6. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    It seems like it works sometimes, but other times it crashes. For instance, this seems like it doesn't crash:
    Code:
    onadd: add_param(6, 6)
    onremove: @param_plus[6] += -6;refresh
    But this does:
    Code:
    onadd: add_param(5, -2)
    onremove: @param_plus[5] += 2;refresh
    Also, what did you mean by "it does exactly nothing"?
     
    #86
  7. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,371
    Likes Received:
    4,942
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    The script does not produce stack level too deep on its own. It is like asking "why my custom damage formula does not work" using support ticket to the official staff instead of asking it in the forum, while the damage formula feature does not actually make your game broken. It's more appropriate if you continue this in your thread you created rather than asking directly to Shaz.

    But let's get back to the question. Your two example shouldn't be that different, however, I suspect there's something within the method refresh that does the stack level too deep. Without going into detail, or even knowing what scripts did you install in your game, let's try to "reconstruct" the add_param method. Try to insert this as a new script.
    Code:
    class Game_Battler
      def add_param_custom(param_id, value)
        @param_plus[param_id] += value
        @hp = [[@hp, mhp].min, 0].max
        @mp = [[@mp, mmp].min, 0].max
      end
    end
    
    Then replace your line to
    Code:
    onremove: add_param_custom(6,6)
    See if it works.
     
    #87
    Ninjakillzu likes this.
  8. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    It seems like it actually works now, both in combat and if I use the commands in an event script call! Thank you so much for your efforts.:smile: Same to @Shaz as well!

    Could you explain why this would work instead of the old refresh method? I honestly don't know much about scripting with ruby.
     
    #88
  9. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,371
    Likes Received:
    4,942
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    I'd go straight answering "I don't know". I don't know what script you install, and they may actually change how the internal system works and whatnot because the method refresh is "shared". What I'm doing is just make a completely separate method that no one is going to touch it no matter how many scripts you install (this could be mean a good/bad thing though).
     
    #89
    Ninjakillzu likes this.
  10. Shaz

    Shaz Veteran Veteran

    Messages:
    37,710
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    It's very odd, because when you added p $1 to my script, it clearly showed that that part of my script was being run over and over and over. I don't know if you just had many battles before it crashed and most of that output was from the successful ones, or if it was somehow looping, as if the remove_state logic was being called repeatedly.

    I hope it continues to work for you. If it starts happening again, it might be necessary for you to just create a dummy map with an enemy that causes it to crash, then load your game up for us to take a look at.
     
    #90
    Ninjakillzu likes this.
  11. Ninjakillzu

    Ninjakillzu Veteran Veteran

    Messages:
    112
    Likes Received:
    34
    First Language:
    English
    Primarily Uses:
    RMVXA
    The part being run over and over took place in the span of a couple seconds or so, in a single battle. This also took place shortly after loading a saved game. It must've been looping like you said.
     
    #91
  12. Shaz

    Shaz Veteran Veteran

    Messages:
    37,710
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    You said you looked back through the thread and didn't find anything, but I can see some comments on page 2 about recursion and stack errors, and a suggested fix. Did you see them, and did you try them? The script formatting has been messed up long ago by a forum move, so here it is in a better format:

    Code:
      #-------------------------------------------------------------------------- 
      # * Clear State Information 
      #-------------------------------------------------------------------------- 
      alias shaz_state_commands_clear_states clear_states 
      def clear_states
        last_states = @states
        shaz_state_commands_clear_states
        last_states.each {|state_id| state_remove_command(state_id) } if last_states
      end
     
      #--------------------------------------------------------------------------
      # * Erase State
      #--------------------------------------------------------------------------
      def erase_state(state_id)
        remove = state?(state_id)
        super
        state_remove_command(state_id) if remove
      end
    
    If it starts to happen again, you can replace these two methods in the script with the above code to see if it fixes it.
     
    #92

Share This Page