IndexError: list index out of range

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Elliot Dreemurr
Newbie
Posts: 17
Joined: Fri Aug 13, 2021 5:38 pm
Projects: Only You
Discord: 💙 Elliot/Ellie Dreemurr 💙#2000
Contact:

IndexError: list index out of range

#1 Post by Elliot Dreemurr »

sooo im trying 2 replicate the doki doki literautre club poem minigame and it was working just fine but now its suddenly not working
removing "(word)" in line 50 kinda fixes it but then every slot shows only the last word on my list (refer 2 screenshot)
im a total amateur with renpy so idk anything about complex stuff so would appreciate whatever help i can get XD

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 15, in script call
    call socialgame
  File "game/socialgame.rpy", line 31, in script
    python:
  File "game/socialgame.rpy", line 49, in <module>
    word = random.choice(wordlist)
IndexError: list index out of range

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 15, in script call
    call socialgame
  File "game/socialgame.rpy", line 31, in script
    python:
  File "renpy/ast.py", line 923, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2235, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/socialgame.rpy", line 49, in <module>
    word = random.choice(wordlist)
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/random.py", line 277, in choice
  File "renpy/python.py", line 992, in __getitem__
    rv = list.__getitem__(self, index)
IndexError: list index out of range

Windows-10-10.0.19041
Ren'Py 7.4.8.1895
Only You 1.0
Fri Aug 13 19:59:10 2021
here is also the txt file of the words list

Code: Select all

#File format: word,ePoint,jPoint,rPoint

#Etona's words
pretty,1,0,0
flower,2,0,1
bubbles,1,0,0
happy,2,0,1
cute,1,0,0
lazy,1,0,0
pleasant,2,0,1
cookie,1,0,0

#Jamison's words
running,0,1,0
surgery,0,1,0
alone,1,2,0
depression,1,2,0
boring,0,2,0
mistake,0,1,0
careless,0,1,0
medicine,0,2,1
control,2,0,0

#Roomba's words
friendship,1,0,2
joy,1,0,2
love,1,0,2
coffee,0,1,2
relationship,0,1,2
money,0,0,1
shop,0,0,1
good,1,0,2
Attachments
unknown.png

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: IndexError: list index out of range

#2 Post by hell_oh_world »

Is wordlist empty? I'm guessing that's causing the issue there.

User avatar
Elliot Dreemurr
Newbie
Posts: 17
Joined: Fri Aug 13, 2021 5:38 pm
Projects: Only You
Discord: 💙 Elliot/Ellie Dreemurr 💙#2000
Contact:

Re: IndexError: list index out of range

#3 Post by Elliot Dreemurr »

oh my bad i forgot 2 include all the code stuff lol

Code: Select all

init python:
    import random

    class SocialWord:
        def __init__(self, word, ePoint, jPoint, rPoint):
            self.word = word
            self.ePoint = ePoint
            self.jPoint = jPoint
            self.rPoint = rPoint

    full_wordlist = []
    with renpy.file('SocialWords.txt') as wordfile:
        for line in wordfile:

            line = line.strip()

            if line == '' or line[0] == '#': continue

        x = line.split(',')
        full_wordlist.append(SocialWord(x[0], int(x[1]), int(x[2]), int(x[3])))

label socialgame(transition=True):
    stop music fadeout 2.0
    scene grey with fadeoutslow
    show screen quick_menu
    #play music
    $ config.skipping = False
    $ config.allow_skipping = False
    if chapter == 1:
        call screen intro("What is everyone up to these days?\n\nPick out posts that you're friends\n have shared and pertain to whomever you like most!", ok_action=Return())
    python:
        progress = 1
        numWords = 25
        wordlist = list(full_wordlist)
        ePoint=0
        jPoint=0
        rPoint=0

        ystart = 160
        while True:
            pstring = str(progress)
            ui.text(pstring + "/" + str(numWords), style="socialgame_text", xpos=810, ypos=80, color='#000')
            for j in range(2):
                if j == 0:
                    x = 440
                else:
                    x = 680
                for i in range(3):
                    word = random.choice(wordlist)
                    wordlist.remove
                    ui.textbutton(word.word, clicked=[ui.returns, SetVariable('ePoint', ePoint+word.ePoint), SetVariable('jPoint', jPoint+word.jPoint), SetVariable('rPoint', rPoint+word.rPoint)], xpos=x, ypos=i * 56 + ystart)

            t = ui.interact()
            r = random.randint(0, 10)
            progress += 1
            if progress > numWords:
                renpy.jump('points')

    label points:

        if jPoint > rPoint and jPoint > ePoint:
            $ winner = 'j'
        elif rPoint > ePoint:
            $ winner = 'r'
        else:
            $ winner = 'e'

        $ config.allow_skipping = True
        $ allow_skipping = True
        stop music fadeout 2.0
        hide screen quick_menu
        scene black with dissolveslow
        pause 1.0
        return

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: IndexError: list index out of range

#4 Post by hell_oh_world »

Looks okay to me. Only this part...

Code: Select all

x = line.split(',')
full_wordlist.append(...
Should be tabbed inside the loop.

User avatar
Elliot Dreemurr
Newbie
Posts: 17
Joined: Fri Aug 13, 2021 5:38 pm
Projects: Only You
Discord: 💙 Elliot/Ellie Dreemurr 💙#2000
Contact:

Re: IndexError: list index out of range

#5 Post by Elliot Dreemurr »

srry 4 being a literal noob and not knowing what anything means but what does "tabbed inside the loop" mean? where should i put it?

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: IndexError: list index out of range

#6 Post by hell_oh_world »

you have a for loop in your code and those two lines that I mentioned should be indented 1 tab (select those two lines and press tab) so that it will go inside the for loop.

User avatar
Elliot Dreemurr
Newbie
Posts: 17
Joined: Fri Aug 13, 2021 5:38 pm
Projects: Only You
Discord: 💙 Elliot/Ellie Dreemurr 💙#2000
Contact:

Re: IndexError: list index out of range

#7 Post by Elliot Dreemurr »

yaaay it finally works! thank u very much 4 the help

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], NoFanru