How to check if an @ has changed? (RGSS1)

Hey guys,

I'm having an odd problem. When I add states to an actor, they get applied but immediately removed again right after. And I can't figure out where or why the states are getting removed.

How can I write a small method that prints a message each time @states is changed? For example, in Game_Battler I tried:

def self.states

p @states

return @states

end

But that does nothing.

Trying to track down where on earth @states is getting cleared... Because if I do a "p @states" at the end of def add_state, it shows me just fine that they were added. But somehow they're gone again right after.

Thanks in advance. 🙂
Something like that is just going to tell you that the state was changed. You already know that. What you want to know is what's causing the state to be changed. Something that tells you it's changed won't tell you WHAT changed it. You could put p @states in def remove_state, but that will only tell you it's being removed, not what's triggering it.


Sounds like you have a script that is updating your states.


What do you mean by "removed again right after"? Are they being added and removed straight away, or are you only noticing after a battle action happens?


Do a global search (Control+Shift+F) for remove_state and see what comes up.
You could do it like this:

class Game_Event

  alias :my_script_update :update unless $@

  def update

    # Store current value for later comparison

    value = @value

    # Call original or alias of other Update methods

    my_script_update

    # Check for a changed value

    if value != @value

      # Do your changes here

      my_method

    end

  end

  def my_method

    # Do your changes n stuff here

    @value = (modify value)

  end

end
Are you using remove by restriction by chance? Whenever I use remove by restriction that is exactly what RPGMaker does in my game. I'm not sure if either the documentation on how remove by restriction works is misleading, but that is what happens when I use remove by restriction.

And yes, I tested that on the default confusion state in a clean project, so it is not a script conflict (before anyone asks).
The OP is asking about RMXP (RGSS1 mentioned). Do you think they would work the same way (assuming your test was done in Ace)
The OP is asking about RMXP (RGSS1 mentioned). Do you think they would work the same way (assuming your test was done in Ace)
I *knew* needed more caffeine in me! 😛

Still, if said feature exists in XP (I don't know if it does), might be worth investigating.
Something like that is just going to tell you that the state was changed. You already know that. What you want to know is what's causing the state to be changed. Something that tells you it's changed won't tell you WHAT changed it. You could put p @states in def remove_state, but that will only tell you it's being removed, not what's triggering it.

Sounds like you have a script that is updating your states.

What do you mean by "removed again right after"? Are they being added and removed straight away, or are you only noticing after a battle action happens?

Do a global search (Control+Shift+F) for remove_state and see what comes up.
Yeah, I did. def remove_state is not what is causing it, strangely. That method is not called after the states are added with def add_state.

Basically in Turn 0 I run a Common Event that adds some states on actor 1 manually. I run a "p $game_party.actors[0].states" immediately after that, and the states are gone. So something happens immediately after running def add_state that removes the states again, apparently. This only happens when restarting a battle (I wrote a script that allows you to retry the battle if you lose):

def retry_battle Audio.me_fade(10) $scene.load_battle_stats $game_system.se_play($data_system.battle_start_se) $game_system.bgm_stop $game_system.bgm_play($game_system.battle_bgm) $scene = Scene_Battle.new end def load_battle_stats filename = $appPath + "/" + "BattleProcess.rxdata" unless FileTest.exist?(filename) return end file = File.open(filename, "rb") $game_switches = Marshal.load(file) $game_variables = Marshal.load(file) $game_actors = Marshal.load(file) $game_party = Marshal.load(file) $game_troop = Marshal.load(file) $game_player = Marshal.load(file) file.close endStates otherwise added work fine. It's just the Turn 0 thing that goes wrong.

Of course this happens before applying the states and before the battle starts again. 🙂

Let me try that script you gave me...
Nope, that script doesn't help.

Okay, this fixed it. Instead of using the "Change State" command, I made states an attr_accessor instead of attr_reader and simply used this code:

$game_party.actors[0].states = [2,3]

Now that works fine. Anyone have an idea why the Change State code didn't work but this does? xD Going to see if any other problems arise...

EDIT

Okay, this is weird... I think there's some deeper issue going on...

After this change, the states don't seem to disappear over time. If I print @states_turn in def remove_states_auto, it appears empty after retrying the battle. Maybe there's a different set of battlers being created? So confused. s__s *researches*

EDIT

Fixed it. Had to define "@states_turn" separately, of course. Yeuy. :3
[...] def load_battle_stats filename = $appPath + "/" + "BattleProcess.rxdata" unless FileTest.exist?(filename) return end file = File.open(filename, "rb") $game_switches = Marshal.load(file) $game_variables = Marshal.load(file) $game_actors = Marshal.load(file) $game_party = Marshal.load(file) $game_troop = Marshal.load(file) $game_player = Marshal.load(file) file.close end
When you load $game_party / $game_actors in the RPG Maker XP you also have to call $game_party.refresh to synchronize your party members with the actor list. Otherwise your party members become separate actor objects.
Cinnamon, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


Just edit your post and add the extra information.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-if-an-has-changed-rgss1.36178/