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:
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:
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:
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
The 5S project (Smallest Spaceships Supporting Specific Speeds) is now maintained by AforAmpere. The latest collection is hosted on GitHub and contains well over 1,000,000 spaceships.
Semi-active here - recovering from a severe case of LWTDS.