ID:1074901
 
(See the best response by Kaiochao.)
I'm wondering about infinite loops in regard to this paragraph in the DM reference page on world.loop_checks:

You may need to disable this feature if your code has some very long loops in it. Before doing that, make sure it's not infinitely long! Your program will utterly crash if it runs out of system stack space, which can happen in a very deep or infinite recursion.


I'm just wondering about how many recursions it would take for stack space to run out, and what needs to be done for something like a ticker to safely run "forever." Specifically, is there a difference regarding this issue in the following code pieces:

//ex. 1
proc/Ticker()
sleep(10)
DoSomething()
Ticker()

//ex. 2
proc/Ticker()
sleep(10)
DoSomething()
return Ticker()

//ex. 3 (this one is silly)
proc/Ticker()
sleep(10)
DoSomething()
TickerStarter()

proc/TickerStarter()
spawn() Ticker()
Just don't base infinite loops on recursion and you won't have a problem. Nowadays, I have one game loop that calls a per-tick proc for each datum added to it. One infinite loop using for() or while(true) for as many tickers as I need.
I see, so the problem is calling a proc over and over within itself, where each iteration never returns?
I did a few tests on recursion limits and I found that after 200 recursions, if you have not indicated an end, the DM will assume it's infinite and cut out. It may have just been because of the type of loop I was doing, but it might give you a start.
Best response
Well, there's a thing called a "call stack" that's given in runtime errors. If your code is like this:
proc/some_proc()
other_proc()

proc/other_proc()
blah()
blah()

proc/blah()
bloop()

And you call some_proc(), the call stack for bloop() would be:
bloop()
called by blah()
called by other_proc()
called by some_proc()


However, when you do recursion, your call stack looks more like this:
proc/loop()
loop()

loop()
called by loop()
called by loop()
called by loop()
called by loop()
...

DM doesn't like that.
Right, thanks for the clarification.