I recently encountered a bug in my randomization code that I can't seem to fix. My code randomizes a variable from a list, and based on that variable chooses a storyline that the game will then start going through, one part per day in the game. I used a looping structure to do this, but the game sometimes says there is an infinite loop.
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/day cycle.rpy", line 231, in script
$ neutral_stories = random.choice(neutral_stories_list)
Exception: Possible infinite loop.
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/day cycle.rpy", line 231, in script
$ neutral_stories = random.choice(neutral_stories_list)
File "C:\Users\Aviala\Desktop\renpy-6.99.11-sdk\renpy\execution.py", line 54, in check_infinite_loop
raise Exception("Possible infinite loop.")
Exception: Possible infinite loop.
There should be enough storylines to last for the entire duration of the demo, but it crashes at seemingly random places - most of the time I can actually get through the whole demo without any problems, but about every 3rd playthrough the game crashes. I haven't found any correlation with any specific storyline and crashing, it seems to be caused by something in the structure, maybe?
I only pasted parts of my code here since I have thousands of lines of it, but this should show you the structure I'm using:
Code: Select all
init python:
barber = False
barber_done = False
barber_end = False
barber_condition = False
#this variable tracks if storyline was NOT done today; sort of "inverted" false and true
barber_not_today = True
neutral_stories_list = ['barber!', 'cult!', 'glitter!', 'wolf!', 'kittens!', 'libraryfire!', 'turnips!']
label audience_phase_cont:
#if 2 story parts are done, the day ends
if stories_today == 2:
jump audience_phase_ends
#check if there are storylines going on; if so, it fills a slot
label continued_storylines:
if barber == True:
if barber_not_today == True:
$ storyline_slots += 1
#if all slots aren't full, add a story
if storyline_slots <= 2:
jump storyline_starters
#if all slots are full, start a story
if storyline_slots == 2:
jump audience_phase_start
label storyline_starters:
if len(neutral_stories_list) >= 0:
$ neutral_stories = random.choice(neutral_stories_list)
else:
# I added this line to test what was happening, and ended up getting it a lot; apparently the list gets emptied prematurely somehow, but that shouldn't be possible? This prevents the game from crashing because of the list index out of range error, and ends the game prematurely.
"The neutral_stories_list is empty now."
"Idk what is happening. It shouldn't be empty."
return
if neutral_stories == 'barber!':
#if barber storyline isn't already active and it's not done already, make it active
if barber == False:
if barber_done == False:
$ barber = True
$ storyline_slots += 1
jump audience_phase_cont
#if the randomization picks a story that is already done, it tells to pick another
if barber_done == True:
if 'barber!' in neutral_stories_list:
$ neutral_stories_list.remove('barber!')
jump storyline_starters
else:
jump audience_phase_start
Code: Select all
label audience_phase_start:
scene bg gameplay
if barber and barber_not_today == True:
if barber_condition == "slaponwrist":
s "Your Grace. A moment?"
#etc, text continues but I cut it cause it's not relevant
jump barber_end
if barber_condition == False:
show wizard with dissolve
show wizard with dissolve
play music "sounds/gameplay1.mp3" fadein 1.0
w "Hey, bossss."
#first part of storyline, text continues but I cut it cause it's not relevant
$ barber_condition = "slaponwrist"
jump barber_end
label barber_end:
if barber_done == True:
$ storyline_slots -= 1
$ barber = False
#I tried to put stuff here but commented it out because it didn't work
#if 'barber!' in neutral_stories_list:
#$ neutral_stories_list.remove('barber!')
$ stories_today += 1
$ barber_not_today = False
jump audience_phase_cont
#"barber storyline part ends"
#"we're gonna move to the next day now, to the neutral storylines"
I've been trying to solve this for hours and hours, but I have no idea what's causing the "IndexError: list index out of range" error. I would really appreciate any help or ideas on what could be causing this.