For loop keeps on repeating itself

Twine Version: 2.8.1

Error: <>: exceeded configured maximum loop iterations (1000)

My for loop keeps on repeating itself when it should’ve stopped long before it reached the maximum. It’s even more baffling because it is a copy and paste of another for loop of mine that works perfectly, but this loop doesn’t for some reason. All I did was change two words. I did another copy and paste, changed the same words to something diff, and it works just fine.

<<for _i = 0; _i < $NPC.length; _i++>>
<<if $NPC[_i].role == "deputy">>
$NPC[_i].name $NPC[_i].sname<br>
<<if $NPC[_i].gender == "man">>
<</if>> has $NPC[_i].haircolor hair.<<if $NPC[_i].mentor == "taken">><br>
<<if $NPC[_i].gender == "man">>
<</if>> apprentice is <<for _i = 0; _i < $pfammen.length; _i++>>
<<if $pfammen[_i].role is "deputy">>
$pfamapp[_i].name $pfamapp[_i].sname

The thing I changed was the two “deputy” cause it was originally “leader” which works. “doctor” also works. “deputy” isn’t working somehow. It just repeats it endlessly. The output is

Briar Meadows
He has black hair.
His apprentice is Caleb Hills

and then it repeats until it reaches maximum. It’s supposed to just return those three lines, like my other two for loops. There’s only one deputy, one leader, and one doctor NPC too

I think I’m seeing an extra if closing tag? But I’m still very new to coding

Edit: NM, I missed an opening tag :sweat_smile:

I suspect your problem is that you’re using _i in both loops. So that will be the same variable: if the inner loop runs it’ll mess up the loop counter for the outer loop…

If you change the inner one to _j does it work?

1 Like

It worked! Unsure why it was only an issue with that one loop, but so far it seems to be working perfect now! Thanks :smiley: