Posts: 1,126
Threads: 43
Joined: May 2009
What is the proper code to avoid that pressing F12 in rmxp an aliased method is aliased again causing the system to crash?
I understand that this happens when one aliases one of the methods in the hidden classes, like Sprite for example.
I'm looking for the code that checks out if the alias has been done, so that i can use it as a condition to decide if aliasing or not.
Posts: 11,214
Threads: 648
Joined: May 2009
It isn't just hidden classes. No - no - no . :cheery:
Place a condition to check an @instance value around your aliased method in question, and immediately set that @instance value to something other than 'nil'.
Code:
#--------------------------------------------------------------------------
# * Fallen Pose
#--------------------------------------------------------------------------
if @derv_anim_bat_stack.nil?
@derv_anim_bat_stack = true
alias mnk_collapse collapse
def collapse
if @battler.is_a?(Game_Actor)
mnk_collapse if DEFAULT_ACTOR
mnk_collapse if DEFAULT_COLLAPSE_ACTOR
if DEFAULT_ACTOR_ID != nil
mnk_collapse if DEFAULT_ACTOR_ID.include?(@battler.id)
end
else
mnk_collapse if DEFAULT_ENEMY
mnk_collapse if DEFAULT_COLLAPSE_ENEMY
if DEFAULT_ENEMY_ID != nil
mnk_collapse if DEFAULT_ENEMY_ID.include?(@battler.id)
end
end
end
end
As you can see (and thanks to SephirothSpawn for showing me this), I wrap an entire method in an if...end block that has a condition....
Code:
if @derv_anim_bat_stack.nil?
@derv_anim_bat_stack = true
---the whole aliased block--
end
which right after it, I set the @derv_anim_bat_stack value to 'true'.
It will only perform this method if the @instance value is nil, whereupon I set the @instance to something else. And, yeah. This part of Animated Battlers did create the dreaded F12 crash years ago until this fixed it.
Posts: 1,126
Threads: 43
Joined: May 2009
I see. This is an option, thank you very much. I was wondering if there is something in Ruby that has been introduced specifically for this purpose. Something involving a defined? call, you know, this method that tells you if a name corresponds to a class, a variable, a method, a constant or nothing. But I had no luck trying to do it this way.
I guess I'm going to go with the solution you suggested but I'm still interested in knowing if there's some other way to do it. So if anyone has other inputs... :)
Posts: 1,664
Threads: 391
Joined: May 2009
Hmm, I'm not sure if this would work. Check out
method_defined? @ ruby-doc.org. :P
Posts: 11,214
Threads: 648
Joined: May 2009
method_defined?
That sounds more like a call to see if a method exists within a class rather than checking to see if one has been aliased.
If that is the case, the statement would be useful to see if someone created a new method in their kickin' script for an existing class and you (as a scripter) was performing a compatibility check for that kickin' script.
Posts: 299
Threads: 9
Joined: May 2009
There's a simpler way - there is actually a method for this in fact.
method_defined
When you alias you define a method, such as - - alias wy_main main
So we can do:
unless method_defined?(wy_main)
alias wy_main main
end
Or simpler still just
alias wy_main main unless method_defined?(wy_main)
I can't believe that a couple of years ago Trickster made a "disable F12" script and everyone used it as a fix for this :x
Edit: wha- where did those posts come from o.O
Posts: 11,214
Threads: 648
Joined: May 2009
Interesting.
So by using:
method_defined?(wy_main)
... we can perform a check for an aliased method assuming we know that the actual alias statement looks for the 'new' method name rather than the name of the original method.
Nice.