ConwayLife.com - A community for Conway's Game of Life and related cellular automata
Home  •  LifeWiki  •  Forums  •  Download Golly

Script request thread

For scripts to aid with computation or simulation in cellular automata.

Re: Script request thread

Postby muzik » August 31st, 2017, 11:30 am

I've been trying to make the phaselister script, but, being the idiot that I am, I'm getting stuck on step 1. I get an input box with stuff already in it just fine, but when i submit the information I get errors. Tried making it display the inputted variables on the top information bar thing in golly, which leads off into this error right here:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File
"C:\Users\.\Documents\CA\apps\sim\golly-3.0b3-win-64bit\golly-3.0b...\phaselister.py",
line 32, in <module>
g.show(x + y)
TypeError: must be string, not int


So either I'm lazy, not seeing something laughably obvious, or the script is trying to call another script and is getting invalid answers from it.

Here's the script so far, in case it is a fault with it directly:
from glife import validint, inside
from string import lower
import golly as g

selrect = g.getselrect()
if len(selrect) == 0: g.exit("Error: Nothing seems to be selected")

# use same file name as in shift.lua
INIFileName = g.getdir("data") + "shift.ini"
oldparams = "10 10 and"
try:
    f = open(INIFileName, 'r')
    oldparams = f.readline()
    f.close()
except:
    # should only happen 1st time (INIFileName doesn't exist)
    pass

answer = g.getstring("enter rectangle dimensions\n" +
                     "(valid modes are h, default is or):",
                     oldparams, "Shift selection")
xym = answer.split()

# extract x and y amounts
if len(xym) == 0: g.exit()
if len(xym) == 1: g.exit("Supply x and y amounts separated by a space.")
if not validint(xym[0]): g.exit("Bad x value: " + xym[0])
if not validint(xym[1]): g.exit("Bad y value: " + xym[1])
x = int(xym[0])
y = int(xym[1])
gens = xym[2]
g.show(x + y)
2c/n spaceships project

Current priorities: see here
muzik
 
Posts: 2565
Joined: January 28th, 2016, 2:47 pm
Location: Scotland

Re: Script request thread

Postby dvgrn » August 31st, 2017, 11:46 am

muzik wrote:I've been trying to make the phaselister script, but, being the idiot that I am, I'm getting stuck on step 1. I get an input box with stuff already in it just fine, but when i submit the information I get errors. Tried making it display the inputted variables on the top information bar thing in golly, which leads off into this error right here:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File
"C:\Users\.\Documents\CA\apps\sim\golly-3.0b3-win-64bit\golly-3.0b...\phaselister.py",
line 32, in <module>
g.show(x + y)
TypeError: must be string, not int

No need to beat yourself up for getting errors -- that happens to everybody.

Also, Python often gives annoyingly irrelevant errors, in cases where the problem is really something like a missing parenthesis on the previous line... so watch out for that as you go forward. In this case Python really is trying hard to explain the actual problem to you, involving g.show(x + y).

g.show needs a string input, but you've put in a number. Whenever this kind of thing comes up, use str() to convert to a string: g.show(str(x + y))... or in this case, g.show("x="+str(x)+", y="+str(y)), or slightly less awkward might be g.show(str([x, y]) .
dvgrn
Moderator
 
Posts: 3938
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI

Re: Script request thread

Postby Saka » September 16th, 2017, 1:17 am

Can someone strip down the nt rule generator script to generate the transitions only? I'm absolutely horrible at classes.
Everyone, please stop posting B/S about CA
The Bugs Range 1 to 100 Project
User avatar
Saka
 
Posts: 2070
Joined: June 19th, 2015, 8:50 pm
Location: In the kingdom of Sultan Hamengkubuwono X

Re: Script request thread

Postby muzik » October 11th, 2017, 5:40 pm

How about something like hexgrid.lua, but for simulating triangular rules?
2c/n spaceships project

Current priorities: see here
muzik
 
Posts: 2565
Joined: January 28th, 2016, 2:47 pm
Location: Scotland

Previous

Return to Scripts

Who is online

Users browsing this forum: No registered users and 2 guests