Stack Level

The following code hates me. 😀

class Scene_Item < Scene_ItemBase

alias a_start start

def start

a_start

end

end

Though this one is fine.

class Scene_File < Scene_MenuBase

  alias a_start start

  def start

    a_start

  end

end

 

 

 

any inputs, folks?
Take out the second one and see if the first works.
You can't use the same alias twice for the same class/method.
The following code hates me. 😀

class Scene_Item < Scene_ItemBase

alias a_start start

def start

a_start

end

end

Though this one is fine.

class Scene_File < Scene_MenuBase

  alias a_start start

  def start

    a_start

  end

end

 

 

 

any inputs, folks?
@shaz: it's different class though...

but maybe the op use a_start alias in Scene_ItemBase or it's superclass too. but not include it in his post. 😀 .
Alias the method after defining it, not before. If you're trying to override a method, you can always use super to refer to the parent method.

Code:
class A  def foo    puts "bar"  endendclass B < A  def foo    puts "before bar"    super    puts "after bar"  endend A.new.foo #=> barB.new.foo #=> before bar\n bar\n after bar
Actually, when you say it "doesn't work", does it give you an actual error message? That might be helpful.
A very large majority of stack level errors are caused by recursive method calls. I'm almost certain that you used that alias name twice within the same class or in the superclass as already stated, so you are stuck in an infinite loop of recursive method calls. Search for the offending alias name and eliminate one of them. There is nothing technically wrong with either piece of code you posted.

It is important to use at least semi-unique names when creating your aliases, especially if you intend to be compatible with other scripts since you not only need to compete with yourself within the namespace, but anyone else potentially using it. Most scripters put a few numbers/abbreviation of their name along with a short string of words indicating the purpose of the alias.

For example:

class Scene_Item < Scene_ItemBase alias start_mith_hook_do_action01 start def start action01 start_mith_hook_do_action01 end def action01 # dont actually name your methods this # stuff and/or things endendIf you had done:
Code:
class Scene_Item < Scene_ItemBase  alias start_old start  def start    other_stuff    start_old   end  def other_stuff # or this, don't use names like this    # stuff and/or things  endend
Then you run the risk of anyone else also following poor naming conventions using the same alias and you run the risk of using it again yourself in the future when you forget that you have already used it. Try not to pollute your namespace like that.You can get stack level errors other ways (though usually there is some kind of recursion involved, and this is by far the most common).
Ah, thanks, folks. Didn't expect to get so much reply. I was only testing some of the built-in operations, so not much effort were put in the naming conventions. I'll update the thread in couple minutes after testing with what I got just now.
Alright, after changing the method name into different ones it runs smoothly now. Naming convention which lead to infinite recursive, it is. 😀

Thanks for all the assist. The problem has been solved, this thread may be closed.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.


Next time, edit your last post instead of double posting 🙂

Original thread: https://forums.rpgmakerweb.com/threads/stack-level.21672/