# Another too much recursion error :(

Continuing the discussion from Too much recursion error help:

Hi All, I’m having some more “too much recursion” error issues. I’m pretty sure it’s going to be related to the one in the above link but in a different place. So I have a fight scene where some of the choices have a random element to them depending on what you choose and it’s also setting up the fight sequence for the opponent, so basically you act, the enemy acts, then it loops back around to reset for another round and then continues. Quick test is ok, but recursion error on random where the highlight is.

How do I handle this? Can anyone see a problem because I can’t see one? How do I get this to pass random test if there isn’t an actual error (it needs to pass to be submitted.) Really appreciate any solutions as this is quite frustrating. Thanks!

Edit: it’s kinda weird that some seeds pass and others don’t even though they’re running through the same sequence. I’m not sure what the issue is?

The rerollraishall logic is probably causing the recursion error. Consider the following scenario:

*rand raishallattack 1 5 gives you the number 3, the rest of the logic happens and previousraishall becomes 3 and you end up on the rerollraishall label again.

*rand raishallattack 1 5 executes again and gives you a 3. Which means that you will get back to the label. The random gives you 3 again and again and again and again. Just because the odds of this happening is small, it doesn’t mean it can’t happen, given that you have a small range of numbers (1-5).

There are multiple ways you can handle this (avoid bad luck). One way of doing this is by “forcing the hand of fate”. If your game logic must have unique subsequent attacks, then you can simply add or subtract one from the roll if they are identical. For example:

``````*label rerollraishall
*rand raishallattack 1 5
*if (raishallattack = previousraishall)
*if (raishallattack = 5)
*set raishallattack 4
*else
*set raishallattack + 1

``````

What this snippet does is add 1 to the roll if previous = current, expect when the roll is 5 and can’t go any higher, in which case it goes to 4. This is a quick and dirty way of doing it. There are more complicated solutions involving arrays where you remember the value you rolled and randomize the remaining values, but you don’t need to overcomplicate things if this solution is satisfactory. Let me know if you need a more robust solution

1 Like

Thanks @quartz I had assumed the problem was at elementpriority (or just below that) because of the random test not getting upset at raishallattack, but you’re right it could be throwing a hissy fit if the raishallattack variable throws up the same number more than twice in a row. Hopefully that’s the source of the randomtest error, if not it’s a potential one so I probably need to fix it anyway to prevent an endless loop if the RNG decides to keep throwing up the same number. Thanks, I’ll try it.

1 Like

There may be another source to the error, but without seeing the full code, it’s hard to tell. There may be some strange edge cases along the way that may keep combat going indefinetely. If you can share the whole code for the combat logic, we can rule out that scenario as well (the random infinite loop can still happen, but there may be others as well).

1 Like

``````*if (choice_randomtest)
*set skip_this_whole_bit true
``````

In A Kiss from Death, randomtest was basically given a full tour of the game this way, resolving anything that required random chance by just skipping to the outcome instead.

2 Likes

@will that’s so cool, I had no idea you could get randomtest to skip sections with rand rolls to prevent these issues (I keep having problems whenever I use it). Thanks I’ll check that out also.

I’ve been too flat out to have a go at either solution but will try and get to it today to see if that’s where the issue is as I think either should hopefully stop that error if that’s where it is. If not I’ll get the whole code out to share.

1 Like

Ok brain’s trust can I please ask again? (Sorry this recursion error that is popping up all through this game is really doing my head in.) This file doesn’t even use the *rand command and I’m still getting an error so unsure what the issue is. Can anyone see the problem? It’s flagging this as the last choice before the error. It’s actually kind of annoying I can’t get full text anymore on randomtest (it just glitches out). Anyone else have this problem or just me? (Works fine so long as I don’t ask for the whole text.)

Link to the whole scene that random test is throwing the hissy fit about.

Edit: I went through the whole game and put an *if more than this many recurs and do something else command, similar to what quartz suggested in spots where it might be problematic and I don’t seem to have any random test errors any more. Not entirely sure why it was flagging the alternatetarget scene as the problem (maybe because you can loop around to keep the character save so it was in one of the starting files without showing the choices leading to it?), but there it is. Hopefully I can’t find any more problems. Thank you both for your help

1 Like

If you have logic that lets the player loop around to the same label without changing anything, it might trigger a recursion error. For example, if you have a combat scene where one of the choices doesn’t do anything (an attack is blocked and doesn’t do any damage and then takes you back to a selection menu), it might mislead you into thinking that there is an infinite loop there. This might be the case, if you have a persistent player. You can avoid these scenarios when doing a random test by checking to avoid picking the same option twice (which might not be possible depending on the type of mini-game you have).

The important thing is to use the results from these tests, think about your game’s structure, and figure out any scenarios where the player might be stuck in an infinite loop. Once you have established that’s not the case, you can skip those parts in the test as Will suggested.

1 Like

Yup. I did a bit more tinkering with cooldowns and things for other options to hopefully avoid some of the short loops from happening enough to trigger off the randomtester when I was dealing with the potential loop above with the *rands. I would have thought traveling through another choice would have been enough to make the tester ok with it, but maybe not? I decided to try and bulletproof it as much as possible in the end and it seemed to stop the errors. I do think the main one was probably the rand loop though. (I really did make this section a bit too complicated with the amount of randomisation that was mixed with stat levels that there were a lot of places for it to bug out. Lessons were learned on building something like this the hard way .)

What was really throwing me out was the random tester was indicating the problem was in different places to where it actually was (sometimes in a different file). I understand now that yes you’re going to have to look at the entire game rather than just where the tester points for these things.

I didn’t actually use the skip that Will suggested this time as I wanted to make sure I understood what the problem actually was rather than potentially leaving a bug in there. Now that I understand what is setting the tester off and if it’s potentially game breaking or just minor tester issue that’s unlikely to cause any bugs in the game itself, I think I could more safely use it in the future.

1 Like