The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => Topic started by: Credt on May 19, 2016, 06:03:26 PM

Title: RMVXA - stack level too deep (com. events)
Post by: Credt on May 19, 2016, 06:03:26 PM
Hello there.

First of all, I'm from Poland, so sorry for my language mistakes in advance. ;)

I have a problem with this error message about "Stack level too deep". Before I decided to ask here, I tried to fix my problem by myself. But I didn't succeed. Then, I looked through the whole Internet to check if there is any solution for my problem. But there's not.

Generally, as I read, the majority of the errors with too deep stack level is caused by the scripts (one duplicated or two not compatible with each other). But in that cases, the error appears after clicking "Playtest" (at the beginning). I can playtest my game without any trouble, however, I created a kind of system which includes a smartphone in my game.

Let me show you, how it works - will be easier to see it instead of trying to describe:
https://youtu.be/Rhpx3H0dum0

And then, I can "click" (switch between apps - it's this characteristic "tap" sound) using arrow keys exactly 85 times before the error appears.

I'll explain how I made this whole system. It is based on Common Events and pictures. Please take a look on that screenshot:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimages.tinypic.pl%2Fi%2F00787%2Faos2zfco7f0e_t.jpg&hash=05ff2dda08cd08d7eb1a12d26fa1cf48a575e0d5) (http://www.tinypic.pl/aos2zfco7f0e)

Each highlighted (chosen) application on the smartphone screen is a different common event (as you can see - com. events 199-207 on my screenshot). When you press a specific arrow key (eg. down), it loads new picture with proper application highlighted. If you are on "Flashlight" app highlighted (top middle, with a bulb icon) and press right arrow key, the picture with lightbulb highlighted will be cleared and new picture (with "Calendar" icon chosen) will be loaded. Then, the player can see it as switching between the apps.
Additionally, I use "Stop All Movement" script by Yanfly to prevent main character from moving when the smartphone is being used.

I'm really sorry for such long explanation, but I did my best to explain my problem as clear as possible for best help results. ;)
I have no idea in which point the stack is being overflowed, because I tried to protect from it using "Break loop", "Jump to label: END" and all this stuff (I consider I'm just stupid and I don't know how to use it correctly). After 85 clicks the error appears, but when I quit using smartphone after eg. 70 clicks and start it again, I can click another 85 times (so the stack is being cleared)...

You are the most experienced guys, I hope you can see something I missed. Probably the solution is quite easy, but I need your assistance... Thanks! :)
Title: Re: RMVXA - stack level too deep (com. events)
Post by: Credt on May 22, 2016, 03:45:00 PM
Hey, I did it!

I understood what was happening all the time and where I overflowed the stack. When using 9 different common events, I looped the whole engine almost infinitely. Then, the game could handle no more than 85 loops before exceeding the limit. Like this:

When button "UP" is pressed - do something - event #1 is running.
    Then, when button "DOWN" is pressed - do something else - events #2 and #1 are running.
        Then, when button "UP" is pressed - do something else again - events #3, #2 and #1 are running.
            [...]
                Then, when button "LEFT" is pressed - do something - events #85, #84, [...], #2 and #1 are running - stack overflowed!


The whole program had no chance to stop, because all common events were still running on the stack.


To fix it, I've made only one common event called "Telephone". Inside, I created 9 different loops, each named by Label (1 to 9). Then, when some button is pressed, the program jumps to the proper label (instead of loading another event) and waits for the next instruction inside a loop. Again, after pressing another button, it just jumps to another label, still inside just one common event, and waits again. After making a choice (eg. if the player would like to turn on a Flashlight app), the whole common event "Telephone" ends with "Exit Event Processing" and that's it!

I tested it by clicking over 200 times and it worked without any errors.
I posted my solution for the future - maybe someone will face a similar problem one day. ;)
Title: Re: RMVXA - stack level too deep (com. events)
Post by: yuyu! on May 23, 2016, 03:30:22 AM
Woo! I'm glad you got it fixed! ^_^ And thanks for sharing your solution! :)