Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

alias stack level too deep [resolved]

Hello, I've been running into a little problem lately: the infamous stack level too deep. I know that it occurs due to loops or putting too many methods on a call stack, but I'm not quite sure how to fix it. The error occurs upon F12 reset and refers to these lines:
Code:
class Game_Player < Game_Character

  attr_accessor :dashing

  attr_accessor :stealthing

  attr_accessor :last_event_id

  

  unless self.method_defined?(:regi_dashstealth_initialize)

    alias regi_dashstealth_initialize initialize

  end

  def initialize

    regi_dashstealth_initialize

    @dashing = false

    @stealthing = false

    @last_event_id = 0

  end

end

 

The error occurs at line 10 here. Thanks for any assistance.
 
it's because when you press F12, CLasses that were loaded are reloaded... and re-use the code you written ->

1st launch
-> Initialize gets renamed to old_init
-> then you use your own init, to call the old one

F12
-> the current Init ( your own ) gets renamed to old_init
-> then you use your own init, to call the old one
But now, the old and the new are the same... and loops forever.

You simply need to check that "old_init" is defined or not to make the alias happen or not.
 
So I plug in something like if old_init == nil before the alias?
Just a sidenote, I copied the format (alias xas_initialize initialize; def initialize; xas_initialize) almost exactly from another existing script (XAS ABS), which does not have the same error when F12 is pressed. Unless there's something I'm missing, why does that code not return an error?
 
Unfortunately adding or removing a ":" didn't fix it.

Thanks for the help, anyway. Maybe I should point out again that other scripts using the exact same format work correctly, while for some reason mine doesn't.
 

Atoa

Member

@BubblesVonSalamancer

This happens because the class Game_Player do not have an initialize.
So you're aliasing it's supe class (Game_Character).

try this:
Code:
class Game_Player < Game_Character

  attr_accessor :dashing

  attr_accessor :stealthing

  attr_accessor :last_event_id

 

  def initialize

    super

    @dashing = false

    @stealthing = false

    @last_event_id = 0

  end

end

you can also try this.
Code:
unless @mehtod_aliasied

  alias ............

  @mehtod_aliasied = true

end
 
I figured it be smarter to ask about something closely related to Bubbles' questions in here and instead of making a new topic, so here goes nothing.

I seen and heard about F12 fix snippet scripts. Can someone redriect me to a good one, such as Zeriab's? The Search function is being no help for me. "F12"...yeah, like that got me anywhere.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top