Is there a way to get around this issue?

For context: I’m creating a turn-based fantasy game where magic spells are based on programming concepts. I’m currently attempting to implement a way to cast for-loop spells that cast on every turn, and allows for if-else commands to be nested within them.

To do this, I made a recursive command parser for my game, and I’ve run into a “maximum call stack size exceeded” crash. If on the app, the game loads endlessly, and on web and mobile, it shows this crash.

Here are screenshots of the event line that causes this issue:
Player Turn Logic External Event:


Parse Command Group External Event:

Parse If External Event:

Specifically, on the third image in the group named “Executing Correct Action Recursive”, the sub group named “causes crash” is the original event line that allows for recursion.

Replacing it with the normal “cast” event line in the next screenshot solves it, but will make it so that if else commands cannot be nested within the for loop.

I’m worried that this error won’t allow me to build the for-loop system that I want in game,and I’m currently looking for solutions or workarounds for this that doesn’t involve straight up rebuilding my game in a different engine due to IRL time constraints among other issues.

Any help would be appreciated!

I’d love to help but I’ve never used recursion. I don’t understand the benifits. Could you use a counter or while or repeat instead? Or maybe add the commands to an array that works like a buffer? That much recursion seems like it might cause lag even if it doesn’t crash. It sounds like the recursion doesn’t have enough exits or ways to end it.

I understand the basics but not the benifits. I think we have different styles and I might not be able to help directly but maybe a little conversation will help other people offer a solution.

My style is more linear. I don’t like external events. I’d rather use functions if events need to be used in different places. Otherwise, I like to keep everything in the main event sheet. It’s easier for me to see the flow without jumping between tabs.