"List index out of range" error, please help
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.
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.
- Hoyoka
- Newbie
- Posts: 4
- Joined: Mon Feb 22, 2016 6:46 am
- Projects: VN Princess of the Lost kingdom
- Location: Slovakia
- Contact:
"List index out of range" error, please help
I am having a problem with my VN. I am getting an error I have never seen before and I tried almost everything to fix it. Maybe it is just a small mistake I did not notice, because I am just a beginner and I am making my first visual novel, so any help would be appreciated.
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 9944, in script
$ karta5 = renpy.random.choice(karty)
File "game/script.rpy", line 9944, in <module>
$ karta5 = renpy.random.choice(karty)
IndexError: list index out of range
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 9944, in script
$ karta5 = renpy.random.choice(karty)
File "C:\Users\AdamVeronika\Downloads\Veronika\renpy-6.99.7-sdk.7z\renpy-6.99.7-sdk\renpy\ast.py", line 805, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\AdamVeronika\Downloads\Veronika\renpy-6.99.7-sdk.7z\renpy-6.99.7-sdk\renpy\python.py", line 1461, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 9944, in <module>
$ karta5 = renpy.random.choice(karty)
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/random.py", line 275, in choice
IndexError: list index out of range
This is line 9944:
$ karta5 = renpy.random.choice(karty)
The block looks like this:
if cards == 4:
$ karta5 = renpy.random.choice(karty)
$ karty.remove(karta5)
show expression karta5 at truecenter with moveinleft
pause 1.0
hide expression karta5
And this is the list named "karty":
$ karty = ["k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9",
"k10", "k11", "k12", "k13", "k14", "k15", "k16", "k17",
"k18", "k19", "k20", "k21", "k22", "k23", "k24", "k25",
"k26", "k27", "k28", "k29", "k30", "k31", "k32", "k33",
"k34", "k35", "k36", "k37", "k38", "k39", "k40", "k41",
"k42", "k43", "k44", "k45", "k46", "k47", "k48", "k49",
"k50", "k51", "k52"]
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 9944, in script
$ karta5 = renpy.random.choice(karty)
File "game/script.rpy", line 9944, in <module>
$ karta5 = renpy.random.choice(karty)
IndexError: list index out of range
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 9944, in script
$ karta5 = renpy.random.choice(karty)
File "C:\Users\AdamVeronika\Downloads\Veronika\renpy-6.99.7-sdk.7z\renpy-6.99.7-sdk\renpy\ast.py", line 805, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\AdamVeronika\Downloads\Veronika\renpy-6.99.7-sdk.7z\renpy-6.99.7-sdk\renpy\python.py", line 1461, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 9944, in <module>
$ karta5 = renpy.random.choice(karty)
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/random.py", line 275, in choice
IndexError: list index out of range
This is line 9944:
$ karta5 = renpy.random.choice(karty)
The block looks like this:
if cards == 4:
$ karta5 = renpy.random.choice(karty)
$ karty.remove(karta5)
show expression karta5 at truecenter with moveinleft
pause 1.0
hide expression karta5
And this is the list named "karty":
$ karty = ["k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9",
"k10", "k11", "k12", "k13", "k14", "k15", "k16", "k17",
"k18", "k19", "k20", "k21", "k22", "k23", "k24", "k25",
"k26", "k27", "k28", "k29", "k30", "k31", "k32", "k33",
"k34", "k35", "k36", "k37", "k38", "k39", "k40", "k41",
"k42", "k43", "k44", "k45", "k46", "k47", "k48", "k49",
"k50", "k51", "k52"]
- Steamgirl
- Veteran
- Posts: 322
- Joined: Sat Jul 28, 2012 4:39 am
- Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
- Projects: Stranded Hearts, Emma: A Lady's Maid
- Deviantart: steamgirlgame
- Contact:
Re: "List index out of range" error, please help
This usually happens if you use an index that is either too high or too low for the list, which starts with 0 and ends with length - 1. But you probably already knew that.
I'm not entirely sure why it thinks it's out of range. Are you defining karty after you run this function? Does it still happen if you do:
$ karta5 = renpy.random.choice(["k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9","k10", "k11", "k12", "k13", "k14", "k15", "k16", "k17","k18", "k19", "k20", "k21", "k22", "k23", "k24", "k25","k26", "k27", "k28", "k29", "k30", "k31", "k32", "k33","k34", "k35", "k36", "k37", "k38", "k39", "k40", "k41","k42", "k43", "k44", "k45", "k46", "k47", "k48", "k49","k50", "k51", "k52"])
?
Also, is renpy/python able to deal with multi-line lists?
I'm not entirely sure why it thinks it's out of range. Are you defining karty after you run this function? Does it still happen if you do:
$ karta5 = renpy.random.choice(["k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9","k10", "k11", "k12", "k13", "k14", "k15", "k16", "k17","k18", "k19", "k20", "k21", "k22", "k23", "k24", "k25","k26", "k27", "k28", "k29", "k30", "k31", "k32", "k33","k34", "k35", "k36", "k37", "k38", "k39", "k40", "k41","k42", "k43", "k44", "k45", "k46", "k47", "k48", "k49","k50", "k51", "k52"])
?
Also, is renpy/python able to deal with multi-line lists?
Hobby Projects: Stranded Hearts | Emma: A Lady's Maid | My Cup of Coffee: The Trouble with Earl Grey
Re: "List index out of range" error, please help
Out of index 'cause you're telling to python to remove karta5 value from the list karty.
If the value is "k11", it turn ASCII into decimal and so go search the 118th element (i think, chances is even higher. K=107 in ASCII).
Use a random number to define the index, and use/remove that item thank to the number.
If the value is "k11", it turn ASCII into decimal and so go search the 118th element (i think, chances is even higher. K=107 in ASCII).
Use a random number to define the index, and use/remove that item thank to the number.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.
10 ? "RENPY"
20 GOTO 10
RUN
10 ? "RENPY"
20 GOTO 10
RUN
Re: "List index out of range" error, please help
It's not because remove doesn't work with values (as opposed to indices). Likelier that the list isn't properly defined before the process.
- Hoyoka
- Newbie
- Posts: 4
- Joined: Mon Feb 22, 2016 6:46 am
- Projects: VN Princess of the Lost kingdom
- Location: Slovakia
- Contact:
Re: "List index out of range" error, please help
Thank you for your replies.
I tried to fix it and I already tried to put the list into one line , but it did not work.
I do not know what else should I try, but it is just a card game I tried to put to my visual novel and it is not necessary for the story, so I guess i should give up on it. Card games are just too difficult for me.
But, I am still very grateful for your answers.
I tried to fix it and I already tried to put the list into one line , but it did not work.
I do not know what else should I try, but it is just a card game I tried to put to my visual novel and it is not necessary for the story, so I guess i should give up on it. Card games are just too difficult for me.
But, I am still very grateful for your answers.
Re: "List index out of range" error, please help
What have you tried thus far?Hoyoka wrote:I do not know what else should I try
If you care about keeping the list ordered:
Code: Select all
$ karta = karty.pop(renpy.random.randrange(len(karty)))
Code: Select all
$ renpy.random.shuffle(karty) # You can do this just once to randomize all items in list.
$ karta = karty.pop()
- Steamgirl
- Veteran
- Posts: 322
- Joined: Sat Jul 28, 2012 4:39 am
- Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
- Projects: Stranded Hearts, Emma: A Lady's Maid
- Deviantart: steamgirlgame
- Contact:
Re: "List index out of range" error, please help
I used this code and it worked fine for me.
The result is ["k1","k3"] or any random combination of 2, depending on which one was removed.
So I don't actually think its converting it to ascii or anything. In fact, having had a look at the official documentation for the two functions they are being used 100% correctly.
Furthermore, this code also works for me!
So it's not a multiline issue.
However, if I do this I get the index out of range issue.
Is it possible that once all the cards are removed it's still trying to remove another one?
I would make this modification to the code and see if that makes the error go away?:
Code: Select all
$ karty = ["k1", "k2", "k3"]
$ karta5 = renpy.random.choice(karty)
$ karty.remove(karta5)
"[karty]"
So I don't actually think its converting it to ascii or anything. In fact, having had a look at the official documentation for the two functions they are being used 100% correctly.
Furthermore, this code also works for me!
Code: Select all
$ karty = ["k1", "k2",
"k3", "k4"]
$ karta5 = renpy.random.choice(karty)
$ karty.remove(karta5)
"[karty]"
However, if I do this I get the index out of range issue.
Code: Select all
$ karty = []
$ karta5 = renpy.random.choice(karty)
$ karty.remove(karta5)
"[karty]"
I would make this modification to the code and see if that makes the error go away?:
Code: Select all
if len(karty) > 0:
$ karta5 = renpy.random.choice(karty)
$ karty.remove(karta5)
else:
"There are no cards left in the list."
Hobby Projects: Stranded Hearts | Emma: A Lady's Maid | My Cup of Coffee: The Trouble with Earl Grey
- Hoyoka
- Newbie
- Posts: 4
- Joined: Mon Feb 22, 2016 6:46 am
- Projects: VN Princess of the Lost kingdom
- Location: Slovakia
- Contact:
Re: "List index out of range" error, please help
Thank you for your advice.
I already made sure that when the list is already empty, it will jump to next turn.
I tried to change the code a bit and it is more simple now, but it does not work.
I changed it to something like this:
$ kar = renpy.random.choice(karty)
$ akarty.append(kar)
$ karty.remove(kar)
But I still get the same error "list index out of range" , it looks like there is some problem with the list named "karty".
I already made sure that when the list is already empty, it will jump to next turn.
I tried to change the code a bit and it is more simple now, but it does not work.
I changed it to something like this:
$ kar = renpy.random.choice(karty)
$ akarty.append(kar)
$ karty.remove(kar)
But I still get the same error "list index out of range" , it looks like there is some problem with the list named "karty".
- Steamgirl
- Veteran
- Posts: 322
- Joined: Sat Jul 28, 2012 4:39 am
- Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
- Projects: Stranded Hearts, Emma: A Lady's Maid
- Deviantart: steamgirlgame
- Contact:
Re: "List index out of range" error, please help
Hmm, when I use the code you pasted originally, it works fine for me. So the real problem is probably elsewhere. If you feel up for it, send me a PM with a download link to your project and I'll see if I can't debug it for you. I promise I won't steal/distribute anything.
Hobby Projects: Stranded Hearts | Emma: A Lady's Maid | My Cup of Coffee: The Trouble with Earl Grey
-
- Newbie
- Posts: 1
- Joined: Mon Jan 04, 2021 8:04 pm
- itch: wickedcadrach
- Contact:
Re: "List index out of range" error, please help
Hi! I'm bumping this because I have the same issue going on with my script. It seems to only fall apart when I do the task a second time though. Anyone who sees this, thanks for any assistance.
Who is online
Users browsing this forum: Bing [Bot]