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)
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