Ren'py - Maximum recursion depth exceeded

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
Hey,

I am currently in development process and I ran into this little problem:

Code:
While running game code:
  File "game/script.rpy", line 1571, in script
   character_variable " In game text"
RuntimeError: maximum recursion depth exceeded in __instancecheck__
Is there a limit I must override? If yes, then how?

Thank you in advance!
 

SillyxRabbit

Newbie
Oct 13, 2016
53
71
You can extend the limit with the following code:
Code:
init python:
    sys.setrecursionlimit(10000)
10000 can be any number you can.
Unless it is intended, you might want to look into what is causing the loop.
 
Oct 30, 2018
395
1,142
I'll hazard a guess that you're either setting a variable to itself or maybe you're stuck in a loop infinitely, thats what's causing the error.

In regards for changing the recursion depth, Python has two methods - sys.getrecursionlimit() which returns the current recursion limit and sys.setrecursionlimit() which allows you to change it, but I seriously wouldn't recommend using either of them, it's pretty dangerous coding and you probably shouldn't be reaching the default recursion limit anyway (1000)

Edit: Ninja'd
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,782
Is there a limit I must override? If yes, then how?
It's a limit that you can override, but it will solve nothing. You get this message because you did something wrong, and you'll still get this message until you solved the problem located at the line 1571 of your script.rpy file.
 
  • Like
Reactions: JohnDupont

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
I'll hazard a guess that you're either setting a variable to itself or maybe you're stuck in a loop infinitely, thats what's causing the error.

In regards for changing the recursion depth, Python has two methods - sys.getrecursionlimit() which returns the current recursion limit and sys.setrecursionlimit() which allows you to change it, but I seriously wouldn't recommend using either of them, it's pretty dangerous coding and you probably shouldn't be reaching the default recursion limit anyway (1000)

Edit: Ninja'd
Thank you both the response!

For what should I look for when checking for a loop?
Except for menu: and animation I don't have anything else.
 

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
It's a limit that you can override, but it will solve nothing. You get this message because you did something wrong, and you'll still get this message until you solved the problem located at the line 1571 of your script.rpy file.
Thank you for the response, but on that line, there is only one character variable and the text (Ex: character "text")
 
Oct 30, 2018
395
1,142
So line 1571 of your script.rpy is

character_variable "in game text"

Can you show us the definition for this character? Because I have a sneaking suspicion that the character is causing the problem.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,782
Thank you for the response, but on that line, there is only one character variable and the text (Ex: character "text")
Don't take Ren'py too much on the letter when it come to errors. Especially for errors like this one. The line number correspond to the moment when Ren'py found that there was an error, not necessarily to the error itself.
By example, when Ren'py detect an endless loop, it will trigger the error anywhere inside of this loop, while the error is in the fact that this part loop to itself.
 

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
So line 1571 of your script.rpy is

character_variable "in game text"

Can you show us the definition for this character? Because I have a sneaking suspicion that the character is causing the problem.
Script.rpy:

Code:
liname " What about the others?! Have you told them your plan?"
Variables.rpy:
Code:
define liname = Character("Liliana" , who_color="#b54db3")
There is no character variable in the patch
 
Oct 30, 2018
395
1,142
Run your program again and see if it crashes on the same line.
  • Check that you haven't set any variables to themselves
  • Check that you aren't stuck in any infinite loops anywhere (code that will always jump back to a label at the start of a block)
If all you've done is menus and animations, the issue might be in you calling in too many new contexts in quick succession, though I admit I'm not sure if that even causes a recursion error, or something else entirely

Edit: Ninja'd again, sort of
 

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
Is line 1571 involved in any kind of condition/loop statements?
Closest is an animation :

Script.rpy:

Code:
image animate_something:
             "images/0.2/dream_23.jpg" with dissolve
             0.8
             "images/0.2/dream_24.jpg" with dissolve
             0.8

             repeat

    show animate_something
    $ renpy.pause ()

As the previous choice menu I have used:
Code:
label search_set:

  
menu:
        " I should check to see if the horses are here." if SearchforHorse == False:
            $ SearchforHorse = True
            scene camp_idle
            " The horses are not here."
            " For their sake, I hope this is not a prank."
            jump search_set

        " I should start the search at once. Time is of the essence.":
            jump hurry

        "There must be a clue or something here that would point me in the right direction.":

            jump search_more_camp
label hurry:
       variables "text"

return  #player is dead

label search_more_camp:
        variables "text"
        jump chapter_two
 
Oct 30, 2018
395
1,142
Code:
image animate_something:
             "images/0.2/dream_23.jpg" with dissolve
             0.8
             "images/0.2/dream_24.jpg" with dissolve
             0.8

             repeat

    show animate_something
    $ renpy.pause ()
Unless it's just me being stupid (which is highly possible), it looks like this is the problem.
I think that 'repeat' might be causing some issues.
 
Oct 30, 2018
395
1,142
Well at least we know I'm still stupid every now and again.

Crazy idea - try moving your 'show animate_something' indentation to the left (so it's in line with your image block).
This might have zero effect, but part of me thinks Ren'Py thinks it is part of the image block and therefore is continuously calling itself.
 

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
I found the problem.
*grabs the popcorn

After the line with 1571 I had a scene and after something like this:
Code:
mrgname " [liname], something I wrote. [j] another thing I wrote."
Apparently, if I remove the second variable from the text ( the [j]) it will work and it will not crash anymore. I've tested it and it worked. So if I have two variables in the text for the same character, le crash...

Yey
Thank you, guys!
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,782
Apparently, if I remove the second variable from the text ( the [j]) it will work and it will not crash anymore. I've tested it and it worked. So if I have two variables in the text for the same character, le crash...
By itself, there's no reason for this to be the problem. You can have as many substitution that you want in a text :
Code:
init python:
    for idx in range( 0, 26 ):
        setattr( store, chr( 97 + idx ), chr( 97 + idx ) )

label start:

    "[a][b][c][d][e][f][g][h][i][j][k][l][m][n][o][p][q][r][s][t][u][v][w][x][y][z]"
    return
So, what hide behind this j variable ? If it's a Character, then the problem probably come from this kind of thing :
Code:
define j = Character( "[j]" )

label blablabla:
    j = renpy.input( "Please, what's your name ?" )
The object use the content of the j variable to find its name, while being stored in the exact same variable.
Magically, Ren'py achieve to correctly see the variable as both a Character object and a string ; mostly because the script is parsed and transformed in something more natural for Ren'py, before the variable become a string.
  • When you've a dialog line, Ren'py address the related entry, which will use the value of j it stored at its creation, so the character object ;
  • When the dialog is displayed, the name will be asked directly to the object ;
  • When you manipulate the j variable, it's the string that is referenced in real time.
But strangely when you try a substitution, Ren'py suddenly only know about the object. So, it ask for the object to give it is name, and the object ask for the j variable, that is itself, to return a string, this string being in fact its own name, and here goes an infinite loop...
 

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
By itself, there's no reason for this to be the problem. You can have as many substitution that you want in a text :
Code:
init python:
    for idx in range( 0, 26 ):
        setattr( store, chr( 97 + idx ), chr( 97 + idx ) )

label start:

    "[a][b][c][d][e][f][g][h][i][j][k][l][m][n][o][p][q][r][s][t][u][v][w][x][y][z]"
    return
So, what hide behind this j variable ? If it's a Character, then the problem probably come from this kind of thing :
Code:
define j = Character( "[j]" )

label blablabla:
    j = renpy.input( "Please, what's your name ?" )
The object use the content of the j variable to find its name, while being stored in the exact same variable.
Magically, Ren'py achieve to correctly see the variable as both a Character object and a string ; mostly because the script is parsed and transformed in something more natural for Ren'py, before the variable become a string.
  • When you've a dialog line, Ren'py address the related entry, which will use the value of j it stored at its creation, so the character object ;
  • When the dialog is displayed, the name will be asked directly to the object ;
  • When you manipulate the j variable, it's the string that is referenced in real time.
But strangely when you try a substitution, Ren'py suddenly only know about the object. So, it ask for the object to give it is name, and the object ask for the j variable, that is itself, to return a string, this string being in fact its own name, and here goes an infinite loop...
As always, you are a lifesaver. I've recently introduced the "custom name " feature.

I've used:

Variable.rpy

Code:
define j = Character("[j]" , who_color="#58aa53")
define sname = Character("[j]")
script.rpy:
Code:
label start:

$ j = renpy.input("Name the main character:")
    $ j = j.strip()
Have I messed up?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,782
Have I messed up?
Yes.


Code:
define j = Character("[j]" , who_color="#58aa53")
This one will always fail is you try to use j for text substitution and is the reason of the crash you got. Change to something like this :
Code:
define j = Character("[jName]" , who_color="#58aa53")
obviously, remember to also change the lines where you use renpy.input to ask the name.


Code:
define sname = Character("[j]")
Normally (it's late and I have a headache) this one shouldn't be a problem. When trying to figure the name of the character, Ren'py will ask for a string coming from j and will obtain the name of the character stored in the said j variable.
 

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
924
3,912
Yes.



This one will always fail is you try to use j for text substitution and is the reason of the crash you got. Change to something like this :
Code:
define j = Character("[jName]" , who_color="#58aa53")
obviously, remember to also change the lines where you use renpy.input to ask the name.




Normally (it's late and I have a headache) this one shouldn't be a problem. When trying to figure the name of the character, Ren'py will ask for a string coming from j and will obtain the name of the character stored in the said j variable.
Thank you mate! You are the best!