ID:148280
 
I keep getting this error message when people are playing my game. What should i do?

runtime error: Maximum recursion level reached (perhaps there is an infinite loop)
To avoid this safety check, set world.loop_checks=0.
proc name: PlayerDeathCheck (/mob/proc/PlayerDeathCheck)
usr: Vash the Stampede (/mob/blue)
src: Pink Slime (/mob/monster/Pink_Slime)
call stack:
Pink Slime (/mob/monster/Pink_Slime): PlayerDeathCheck()
Pink Slime (/mob/monster/Pink_Slime): NPCAttack()
Pink Slime (/mob/monster/Pink_Slime): NPCDeathCheck()
Pink Slime (/mob/monster/Pink_Slime): Attack()
Pink Slime (/mob/monster/Pink_Slime): CommencedBattle()
Pink Slime (/mob/monster/Pink_Slime): Battle()
Pink Slime (/mob/monster/Pink_Slime): PlayerDeathCheck()
Pink Slime (/mob/monster/Pink_Slime): NPCAttack()
Pink Slime (/mob/monster/Pink_Slime): NPCDeathCheck()
Pink Slime (/mob/monster/Pink_Slime): Attack()
...
Pink Slime (/mob/monster/Pink_Slime): Attack()
Pink Slime (/mob/monster/Pink_Slime): Battle()
Pink Slime (/mob/monster/Pink_Slime): NPCAttack()
Pink Slime (/mob/monster/Pink_Slime): Attack()
Pink Slime (/mob/monster/Pink_Slime): Battle()
Pink Slime (/mob/monster/Pink_Slime): NPCAttack()
Pink Slime (/mob/monster/Pink_Slime): Attack()
Pink Slime (/mob/monster/Pink_Slime): Battle()
Vash the Stampede (/mob/blue): Bump(Pink Slime (/mob/monster/Pink_Slime))


Also, when this comes up, the battle system stops for the person it happens to. If u need my battle system code, i can give it to u.
Maximum recursion errors are because of the way you're handling your battles.

Battle() is, I assume, ultimately calling the proc or verb that handles the spell list, and yet you call it when the player clicks Cancel(). Likewise you call it from inside Attack(). The solution: Don't. Use Battle() to call other procs, and let them return on their own.

Another disturbing trend in your code is that you're using two different attack and death check procs. You don't need to. These things should be handled in a very different way.
proc/Attack(mob/target)
...

proc/DeathCheck(mob/killer)
...

Lummox JR
Hmm... It seems you have an infinite loop (thank me for pointing out the obvious, lol). Perhaps you're doing this:

<code> label_thingy if(something==something_else) goto label_thingy </code>

Yours is probably a bit more complex, but this might be the problem. Sorry I don't have an answer, but it might help you narrow down the problem.
In response to Cybermattr
Cybermattr wrote:
Hmm... It seems you have an infinite loop (thank me for pointing out the obvious, lol). Perhaps you're doing this:
<dmlabel_thingy
if(something==something_else)
goto label_thingy</dm>>
Yours is probably a bit more complex, but this might be the problem. Sorry I don't have an answer, but it might help you narrow down the problem.

That wouldn't be it; a simple loop does not cause recursion. (And if he's using goto to do loops, he has bigger problems.) Recursion is when a proc calls itself (directly or indirectly), and infinite recursion is when that happens so much that the stack overflows.
proc/CrashHappy()
world << "Whee! I'm doing something!"
sleep()
CrashHappy()
In these cases recursion can usually be avoided by using an actual loop, or by using spawn() to call the proc.

Lummox JR
In response to Lummox JR
I got something like this

mob
proc
Battle()
usr.lib = 1
if(usr.defend == 1)
usr.defense /= 2
usr.defend = 0
switch(alert("Enemy encountered! Command?",,"Commence Battle","Defend","Run"))
if("Commence Battle")
CommencedBattle()
if("Defend")
usr.defense *= 2
usr.defend = 1
NPCDeathCheck()
if("Run")
Run()

CommencedBattle()
switch(alert(usr,"Command?",,"Attack","Spell","Item"))
if("Attack")
Attack()
if("Spell")
usr << "<font color = blue>Metroid is working on this</font color = blue> (because i still havent figured out the damn spells)"
Battle()
if("Item")
Item()

what's my problem here thats causing an infinate loop?
In response to Metroid
Metroid wrote:
I got something like this

mob
proc
Battle()
...
if("Commence Battle")
CommencedBattle()
...
CommencedBattle()
...
if("Spell")
usr << "<font color = blue>Metroid is working on this</font> (because i still havent figured out the damn spells)"
Battle()
...
what's my problem here thats causing an infinate loop?

Battle() calls CommencedBattle(), which in turn calls Battle() (without a spawn()), and so on. Infinite recursion. When the first Battle() proc calls CommencedBattle(), it doesn't end; it hangs on waiting for the results. Eventually you end up with so many procs waiting on results that the game crashes. The same sort of thing happens in your Attack() proc, which is why you got the error message you did.

The solution is to implement a proper loop.
proc/Battle()
var/inbattle=1
do
for(var/mob/M in combatants)
... // prompt characters for attack choices
... // implement their choice
while(inbattle)
... // resolve battle here
Then your attack and spell procs shouldn't call Battle(); they should just return.

You also have one other problem, and it's severe: usr is peppered throughout your procs. Get rid of it. In most cases usr is very very unsafe to use in procs. Be sure you also direct input() to src, not usr, and make sure src.client is valid. (If it isn't valid, choose an attack choice at random or something.)

Lummox JR