Page 1 of 1
Help needed with rectangle lists
Posted: December 1st, 2016, 3:43 am
by Saka
I'm writing a simple script but I have encountered an error: Index is out of range or something like that. I know what it means, but I don't know why it's happening. The most curious thing is that the script works fine in Life and HighLife, but not in other rules, like Day and Night. The problematic part of the code:
Code: Select all
while True:
rand = r.randrange(10, 80)
g.randfill(rand)
g.run(5000)
oldbounds = g.getrect()
g.run(100)
newbounds = g.getrect()
if oldbounds[2] != newbounds[2] or oldbounds[3] != newbounds[3]:
break
Re: Help needed with rectangle lists
Posted: December 1st, 2016, 4:41 am
by wildmyron
Saka wrote:I'm writing a simple script but I have encountered an error: Index is out of range or something like that. I know what it means, but I don't know why it's happening. The most curious thing is that the script works fine in Life and HighLife, but not in other rules, like Day and Night. The problematic part of the code:
Code: Select all
while True:
rand = r.randrange(10, 80)
g.randfill(rand)
g.run(5000)
oldbounds = g.getrect()
g.run(100)
newbounds = g.getrect()
if oldbounds[2] != newbounds[2] or oldbounds[3] != newbounds[3]:
break
The error most likely occurs when the pattern dies out and the population is 0. In this instance g.getrect() will return an empty array and indexing into it will fail. You should test if newbounds is empty before testing the bounding box dimensions.
It's difficult to say if this is the problem because you haven't provided the error message. Even though it doesn't look like it, you can copy the error message with 'Ctrl C' (on Windows). Presumably, the error message was something like this:
Code: Select all
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ariep\AppData\Roaming\Golly\golly_clip.py", line 14, in <module>
if oldbounds[2] != newbounds[2] or oldbounds[3] != newbounds[3]:
IndexError: list index out of range