[Golly][LifeHistory][Perl Scripting] g_setcell

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
DivusIulius
Posts: 89
Joined: April 1st, 2009, 11:23 am
Contact:

[Golly][LifeHistory][Perl Scripting] g_setcell

Post by DivusIulius » May 2nd, 2013, 6:35 pm

Please help! I think I'm going nuts. :wink:

How do I create LifeHistory cells in state e.g. '5' using Perl scripting?

I tried

Code: Select all

g_setcell($x, $y, $state)
but I get a state value is out of range message! Image Just state 0 and 1 are allowed...

And after reading the whole Perl scripting section I'm still clueless...

Any help will be greatly appreciated. :)

User avatar
dvgrn
Moderator
Posts: 11166
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI
Contact:

Re: [Golly][LifeHistory][Perl Scripting] g_setcell

Post by dvgrn » May 2nd, 2013, 7:09 pm

DivusIulius wrote:How do I create LifeHistory cells in state e.g. '5' using Perl scripting?

I tried

Code: Select all

g_setcell($x, $y, $state)
but I get a state value is out of range message! Just state 0 and 1 are allowed.
Multi-state g_setcell() definitely does work fine in Perl, most of the time -- try running invert.pl on a LifeHistory selection, for example.

But I've seen something similar in Python scripting -- drove me crazy on a couple of occasions, too. I think it's always turned out that the rule for the current active layer was set to a two-state universe, for whatever reason -- a new universe had been created, or the active layer had been switched to a two-state layer, or something like that.

Have you tried a g_setrule("LifeHistory") line right before the line you get an error on? Or if you need to keep the current layer as a two-state layer -- though that doesn't make sense if you're using g_setcell(), I suppose -- you could add a new temporary layer, set that layer's rule to LifeHistory, do your work there, and then remove the layer.

This is something of a design limitation for Golly, I think -- it makes it strangely awkward to do certain operations on cell lists. I'll try to remember, and post some details on, the most recent case where I ran into this problem and spent half an hour wondering why I was getting cell-state-out-of-range errors.

Edit: One mistake that I make every now and then that causes the state-out-of-range error is when I maintain a cell list incorrectly -- for example, if I combine two multi-state cell lists directly instead of using g.join(). Sometimes it works fine (i.e., as long as the first list has an odd number of cells, so it doesn't need the extra marker zero at the end).

But it sounds like your problem really is with g_set_cell(), not with g_putcells(), so this is probably not too relevant.

User avatar
Andrew
Moderator
Posts: 981
Joined: June 2nd, 2009, 2:08 am
Location: Melbourne, Australia
Contact:

Re: [Golly][LifeHistory][Perl Scripting] g_setcell

Post by Andrew » May 2nd, 2013, 8:22 pm

DivusIulius wrote:How do I create LifeHistory cells in state e.g. '5' using Perl scripting?
Without seeing the whole script it's difficult to say. This little test works:

Code: Select all

g_new("test LifeHistory");
g_setrule("LifeHistory");
my $state = 5;
g_setcell(0, 0, $state);
If you think the bug is in Golly then please show the entire script (or better, a small script that illustrates the bug).

I suspect you are setting $state incorrectly. Try checking its value with g_note($state) just before the g_setcell call.
Use Glu to explore CA rules on non-periodic tilings: DominoLife and HatLife

User avatar
DivusIulius
Posts: 89
Joined: April 1st, 2009, 11:23 am
Contact:

Re: [Golly][LifeHistory][Perl Scripting] g_setcell

Post by DivusIulius » May 3rd, 2013, 10:24 am

dvgrn wrote:Multi-state g_setcell() definitely does work fine in Perl, most of the time
Andrew wrote:This little test works
dvgrn, Andrew, thanks!

I made an absolutely moronic error:

Here, I was blindly changing 1 with 5. Image

Code: Select all

ORIGINAL: g_setcell($i + ($currentColumn * $spacing), $j + ($currentRow * $spacing), (substr $bin, $next, 1));

BUGGY: g_setcell($i + ($currentColumn * $spacing), $j + ($currentRow * $spacing), (substr $bin, $next, 5));

CORRECT: g_setcell($i + ($currentColumn * $spacing), $j + ($currentRow * $spacing), (substr $bin, $next, 1) * 5);

Post Reply