1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
|
<html>
<title>Golly Help: Perl Scripting</title>
<body bgcolor="#FFFFCE">
<p>
<dd><a href="#install"><b>Installing Perl</b></a></dd>
<dd><a href="#examples"><b>Example scripts</b></a></dd>
<dd><a href="#commands"><b>Golly's scripting commands</b></a></dd>
<dd><a href="#cellarrays"><b>Cell arrays</b></a></dd>
<dd><a href="#rectarrays"><b>Rectangle arrays</b></a></dd>
<dd><a href="#problems"><b>Potential problems</b></a></dd>
<dd><a href="#copyright"><b>Perl copyright notice</b></a></dd>
</p>
<p><a name="install"></a> <br>
<font size=+1><b>Installing Perl</b></font>
<p>
Before you can run a .pl script, Perl needs to be installed on your system.
Mac OS X users don't need to do anything because Perl is already installed.
Windows and Linux users need to have Perl 5.10 or later.
If you are using Linux then you might already have Perl 5.10 installed;
if not, visit <a href="http://www.perl.org/">www.perl.org</a> and download
a suitable installer. Windows users are advised to download the
<a href="http://www.activestate.com/Products/ActivePerl/">ActivePerl</a> installer.
<p>
On Windows and Linux, the Perl library is loaded at runtime (the first time
you try to run a .pl script). Golly initially attempts to load a particular
version of the Perl library: perl510.dll on Windows or libperl.so.5.10
on Linux. The numbers correspond to Perl version 5.10.x.
If that library can't be found then you'll be
prompted to enter a different library name matching the version of Perl
installed on your system. A successfully loaded library is remembered
(in your GollyPrefs file) so you won't get the prompt again unless you
remove Perl or install a new version. If Perl isn't installed then
you'll have to hit Cancel and you won't be able to run any .pl scripts.
<p><a name="examples"></a> <br>
<font size=+1><b>Example scripts</b></font>
<p>
The Scripts folder supplied with Golly contains a number of example Perl scripts:
<p>
<dd>
<table cellspacing=0 cellpadding=0>
<tr>
<td><b>density.pl</b></td><td width=10> </td>
<td> — calculates the density of the current pattern</td>
</tr>
<tr>
<td><b>envelope.pl</b></td><td width=10> </td>
<td> — uses multiple layers to remember a pattern's live cells</td>
</tr>
<tr>
<td><b>giffer.pl</b></td><td width=10> </td>
<td> — creates an animated GIF using the current selection</td>
</tr>
<tr>
<td><b>goto.pl</b></td><td width=10> </td>
<td> — goes to a given generation</td>
</tr>
<tr>
<td><b>invert.pl</b></td><td width=10> </td>
<td> — inverts all cell states in the current selection</td>
</tr>
<tr>
<td><b>oscar.pl</b></td><td width=10> </td>
<td> — detects oscillating patterns, including spaceships</td>
</tr>
<tr>
<td><b>pop-plot.pl</b></td><td width=10> </td>
<td> — displays a plot of population versus time</td>
</tr>
<tr>
<td><b>shift.pl</b></td><td width=10> </td>
<td> — shifts the current selection by given x y amounts</td>
</tr>
<tr>
<td><b>tile.pl</b></td><td width=10> </td>
<td> — tiles the current selection with the pattern inside it</td>
</tr>
<tr>
<td><b>tile-with-clip.pl</b></td><td width=10> </td>
<td> — tiles the current selection with the clipboard pattern</td>
</tr>
</table>
</dd>
</p>
<p>
The easiest way to run one of these scripts is to tick the <b>Show Scripts</b>
item in the File menu and then simply click on the script you wish to run.
You can also select one of the <b>Run</b> items in the File menu.
<p>
When Golly starts up it looks for a script called <b>golly-start.pl</b>
in the same directory as the Golly application and then in a user-specific
data directory (see the <a href="#getdir"><b>g_getdir</b></a> command for
the likely path on your system).
If the script is found then it is automatically executed.
<p>
There are a number of ways to abort a running script. Hit the escape key,
or click on the stop button in the tool bar, or select the Stop item in the
Control menu.
<p><a name="commands"></a> <br>
<font size=+1><b>Golly's scripting commands</b></font>
<p>
This section describes all the Golly-specific scripting commands
that can be used in a Perl script. Commands are grouped by function
(<a href="#filing"><b>filing</b></a>,
<a href="#editing"><b>editing</b></a>,
<a href="#control"><b>control</b></a>,
<a href="#viewing"><b>viewing</b></a>,
<a href="#layers"><b>layers</b></a>
and <a href="#miscellaneous"><b>miscellaneous</b></a>)
or you can search for individual commands alphabetically:
<p>
<dd>
<table cellspacing=0 cellpadding=0>
<tr>
<td valign=top>
<a href="#addlayer"><b>g_addlayer</b></a><br>
<a href="#advance"><b>g_advance</b></a><br>
<a href="#autoupdate"><b>g_autoupdate</b></a><br>
<a href="#check"><b>g_check</b></a><br>
<a href="#clear"><b>g_clear</b></a><br>
<a href="#clone"><b>g_clone</b></a><br>
<a href="#copy"><b>g_copy</b></a><br>
<a href="#cut"><b>g_cut</b></a><br>
<a href="#dellayer"><b>g_dellayer</b></a><br>
<a href="#dokey"><b>g_dokey</b></a><br>
<a href="#duplicate"><b>g_duplicate</b></a><br>
<a href="#empty"><b>g_empty</b></a><br>
<a href="#error"><b>g_error</b></a><br>
<a href="#evolve"><b>g_evolve</b></a><br>
<a href="#exit"><b>g_exit</b></a><br>
<a href="#fit"><b>g_fit</b></a><br>
<a href="#fitsel"><b>g_fitsel</b></a><br>
<a href="#flip"><b>g_flip</b></a><br>
<a href="#getalgo"><b>g_getalgo</b></a><br>
<a href="#getbase"><b>g_getbase</b></a><br>
<a href="#getcell"><b>g_getcell</b></a><br>
<a href="#getcells"><b>g_getcells</b></a>
</td>
<td valign=top width=40> </td>
<td valign=top>
<a href="#getclip"><b>g_getclip</b></a><br>
<a href="#getclipstr"><b>g_getclipstr</b></a><br>
<a href="#getcolor"><b>g_getcolor</b></a><br>
<a href="#getcolors"><b>g_getcolors</b></a><br>
<a href="#getcursor"><b>g_getcursor</b></a><br>
<a href="#getdir"><b>g_getdir</b></a><br>
<a href="#getgen"><b>g_getgen</b></a><br>
<a href="#getkey"><b>g_getkey</b></a><br>
<a href="#getlayer"><b>g_getlayer</b></a><br>
<a href="#getmag"><b>g_getmag</b></a><br>
<a href="#getname"><b>g_getname</b></a><br>
<a href="#getoption"><b>g_getoption</b></a><br>
<a href="#getpop"><b>g_getpop</b></a><br>
<a href="#getpos"><b>g_getpos</b></a><br>
<a href="#getrect"><b>g_getrect</b></a><br>
<a href="#getrule"><b>g_getrule</b></a><br>
<a href="#getselrect"><b>g_getselrect</b></a><br>
<a href="#getstep"><b>g_getstep</b></a><br>
<a href="#getstring"><b>g_getstring</b></a><br>
<a href="#hash"><b>g_hash</b></a><br>
<a href="#help"><b>g_help</b></a><br>
<a href="#join"><b>g_join</b></a>
</td>
<td valign=top width=40> </td>
<td valign=top>
<a href="#load"><b>g_load</b></a><br>
<a href="#maxlayers"><b>g_maxlayers</b></a><br>
<a href="#movelayer"><b>g_movelayer</b></a><br>
<a href="#new"><b>g_new</b></a><br>
<a href="#note"><b>g_note</b></a><br>
<a href="#numalgos"><b>g_numalgos</b></a><br>
<a href="#numlayers"><b>g_numlayers</b></a><br>
<a href="#numstates"><b>g_numstates</b></a><br>
<a href="#open"><b>g_open</b></a><br>
<a href="#opendialog"><b>g_opendialog</b></a><br>
<a href="#parse"><b>g_parse</b></a><br>
<a href="#paste"><b>g_paste</b></a><br>
<a href="#putcells"><b>g_putcells</b></a><br>
<a href="#randfill"><b>g_randfill</b></a><br>
<a href="#reset"><b>g_reset</b></a><br>
<a href="#rotate"><b>g_rotate</b></a><br>
<a href="#run"><b>g_run</b></a><br>
<a href="#save"><b>g_save</b></a><br>
<a href="#savedialog"><b>g_savedialog</b></a><br>
<a href="#select"><b>g_select</b></a><br>
<a href="#setalgo"><b>g_setalgo</b></a><br>
<a href="#setbase"><b>g_setbase</b></a>
</td>
<td valign=top width=40> </td>
<td valign=top>
<a href="#setcell"><b>g_setcell</b></a><br>
<a href="#setclipstr"><b>g_setclipstr</b></a><br>
<a href="#setcolor"><b>g_setcolor</b></a><br>
<a href="#setcolors"><b>g_setcolors</b></a><br>
<a href="#setcursor"><b>g_setcursor</b></a><br>
<a href="#setdir"><b>g_setdir</b></a><br>
<a href="#setgen"><b>g_setgen</b></a><br>
<a href="#setlayer"><b>g_setlayer</b></a><br>
<a href="#setmag"><b>g_setmag</b></a><br>
<a href="#setname"><b>g_setname</b></a><br>
<a href="#setoption"><b>g_setoption</b></a><br>
<a href="#setpos"><b>g_setpos</b></a><br>
<a href="#setrule"><b>g_setrule</b></a><br>
<a href="#setstep"><b>g_setstep</b></a><br>
<a href="#show"><b>g_show</b></a><br>
<a href="#shrink"><b>g_shrink</b></a><br>
<a href="#step"><b>g_step</b></a><br>
<a href="#store"><b>g_store</b></a><br>
<a href="#transform"><b>g_transform</b></a><br>
<a href="#update"><b>g_update</b></a><br>
<a href="#visrect"><b>g_visrect</b></a><br>
<a href="#warn"><b>g_warn</b></a>
</td>
</tr>
</table>
</dd>
</p>
<p><a name="filing"></a> <br>
FILING COMMANDS
<a name="open"></a><p><dt><b>g_open(<i>$filename, $remember=0</i>)</b></dt>
<dd>
Open the given file and process it according to its type:
</dd>
<p><dd>
<ul>
<li>A HTML file (.htm or .html extension) is displayed in the help window.
<li>A text file (.txt or .doc extension, or a name containing "readme")
is opened in your text editor.
<li>A script file (.pl or .py extension) is executed.
<li>A zip file (.zip extension) is processed as described
<a href="formats.html#zip">here</a>.
<li>Any other type of file is assumed to be a pattern file and is loaded
into the current layer.
</ul>
</dd>
<p><dd>
A non-absolute path is relative to the location of the script.
The 2nd parameter is optional (default = 0) and specifies if the given
pattern or zip file should be remembered in the Open Recent submenu,
or in the Run Recent submenu if the file is a script.
</dd>
<dd> Example: <b>g_open("my-patterns/foo.rle");</b></dd>
</p>
<a name="save"></a><p><dt><b>g_save(<i>$filename, $format, $remember=0</i>)</b></dt>
<dd>
Save the current pattern in a given file using the specified format ("rle" or "mc").
A non-absolute path is relative to the location of the script.
The 3rd parameter is optional (default = 0) and specifies if the file
should be remembered in the Open Recent submenu.
If the <b>savexrle</b> option is 1 then extended RLE format is used
(see the <a href="file.html#xrle">Save Extended RLE</a> item for details).
</dd>
<dd> Example: <b>g_save("foo.rle", "rle", 1);</b></dd>
</p>
<a name="opendialog"></a><p><dt><b>g_opendialog(<i>$title, $filetypes, $initialdir, $initialfname, $mustexist=1</i>)</b></dt>
<dd>
Present a standard Open dialog to the user and return the chosen path in a string.
All parameters are optional; the default is an Open dialog showing the current directory,
with a title of "Choose a file" and a file type of "All files (*)|*".
If the 5th parameter (default = 1) is set to 0, the user can specify a new filename
instead of choosing an existing file.
If the given file type is "dir" then the dialog lets the user choose a directory
rather than a file.
If the user cancels the dialog, the return value will be an empty string.
</dd>
<dd> Example: <b>my $fname = g_opendialog('Open MCell File', 'MCell files (*.mcl)|*.mcl', 'C:\\Temp', 'sample.mcl');</b></dd>
<dd> Example: <b>my $dirname = g_opendialog('Choose a folder', 'dir');</b></dd>
</p>
<a name="savedialog"></a><p><dt><b>g_savedialog(<i>$title, $filetypes, $initialdir, $initialfname, $suppressprompt=0</i>)</b></dt>
<dd>
Present a standard Save dialog to the user and return the chosen path in a string.
All parameters are optional; the default is a Save dialog showing the current directory,
with a title of "Choose a save location and filename" and a file type of "All files (*)|*".
If a file already exists at the chosen location, an Overwrite? query will be displayed
unless the 5th parameter (default = 0) is set to 1.
If the user cancels the dialog, the return value will be an empty string.
</dd>
<dd> Example: <b>my $fname = g_savedialog('Save text file', 'Text files (*.txt;*.csv)|*.txt;*.csv', 'C:\\Temp', 'Params.txt', 1);</b></dd>
</p>
<a name="load"></a><p><dt><b>g_load(<i>$filename</i>)</b></dt>
<dd>
Read the given pattern file and return a cell array reference.
</dd>
<dd> Example: <b>$blinker = g_load("blinker.rle");</b></dd>
</p>
<a name="store"></a><p><dt><b>g_store(<i>$cellarray, $filename</i>)</b></dt>
<dd>
Write the pattern in the given cell array reference to the specified file in RLE format.
If the <b>savexrle</b> option is 1 then extended RLE format is used
(see the <a href="file.html#xrle">Save Extended RLE</a> item for details).
</dd>
<dd> Example: <b>g_store($cellarray, "foo.rle");</b></dd>
</p>
<a name="getdir"></a><p><dt><b>g_getdir(<i>dirname</i>)</b></dt>
<dd>
Return the path of the specified directory:
</dd>
<p>
<dd>
<b>"app"</b> — the directory containing the Golly application.
</dd>
<p>
<dd>
<b>"data"</b> — the user-specific data directory:
</dd>
<dd>
<table cellspacing=0 cellpadding=0>
<tr><td>On Linux:</td><td width=10>
</td><td>~/.golly/</td></tr>
<tr><td>On Mac OS X:</td><td width=10>
</td><td>~/Library/Application Support/Golly/</td></tr>
<tr><td>On Windows:</td><td width=10>
</td><td>C:\Documents and Settings\username\Application Data\Golly\</td></tr>
</table>
</dd>
</td></tr>
<p>
<dd>
<b>"temp"</b> — the directory Golly uses to store various temporary files.
All these files are deleted when Golly quits.
</dd>
<p>
<dd>
<b>"rules"</b> — the user-specific rules directory
set in <a href="prefs:control">Preferences > Control</a>.
</dd>
<p>
<dd>
<b>"patterns"</b> — the directory displayed by File > Show Patterns.
</dd>
<p>
<dd>
<b>"scripts"</b> — the directory displayed by File > Show Scripts.
</dd>
<p>
<dd>
<b>"download"</b> — the directory Golly uses to store downloaded files.
</dd>
<p>
<dd>
In each case a full path is returned, terminated by the appropriate path separator
for the current platform.
</dd>
<dd> Example: <b>g_open(g_getdir("app")."Patterns/Breeders/breeder.lif");</b></dd>
</p>
<a name="setdir"></a><p><dt><b>g_setdir(<i>dirname, dirpath</i>)</b></dt>
<dd>
Set the specified directory to the given path (which must be a full path to
an existing directory). All the directory names listed above are allowed,
except for "app", "data" and "temp".
</dd>
<dd> Example: <b>g_setdir("patterns", "/path/to/my-patterns/");</b></dd>
</p>
<p><a name="editing"></a> <br>
EDITING COMMANDS
<a name="new"></a><p><dt><b>g_new(<i>$title</i>)</b></dt>
<dd>
Create a new, empty universe and set the window title.
If the given title is empty then the current title won't change.
</dd>
<dd> Example: <b>g_new("test-pattern");</b></dd>
</p>
<a name="cut"></a><p><dt><b>g_cut()</b></dt>
<dd>
Cut the current selection to the clipboard.
</dd>
</p>
<a name="copy"></a><p><dt><b>g_copy()</b></dt>
<dd>
Copy the current selection to the clipboard.
</dd>
</p>
<a name="clear"></a><p><dt><b>g_clear(<i>$where</i>)</b></dt>
<dd>
Clear inside (where = 0) or outside (where = 1) the current selection.
</dd>
<dd> Example: <b>g_clear(1);</b></dd>
</p>
<a name="paste"></a><p><dt><b>g_paste(<i>$x, $y, $mode</i>)</b></dt>
<dd>
Paste the clipboard pattern at x,y using the given mode ("and", "copy", "or", "xor").
</dd>
<dd> Example: <b>g_paste(0, 0, "or");</b></dd>
</p>
<a name="shrink"></a><p><dt><b>g_shrink()</b></dt>
<dd>
Shrink the current selection to the smallest rectangle enclosing all of the
selection's live cells.
</dd>
</p>
<a name="randfill"></a><p><dt><b>g_randfill(<i>$percentage</i>)</b></dt>
<dd>
Randomly fill the current selection to a density specified by the given
percentage (1 to 100).
</dd>
<dd> Example: <b>g_randfill(50);</b></dd>
</p>
<a name="flip"></a><p><dt><b>g_flip(<i>$direction</i>)</b></dt>
<dd>
Flip the current selection left-right (direction = 0) or top-bottom (direction = 1).
</dd>
</p>
<a name="rotate"></a><p><dt><b>g_rotate(<i>$direction</i>)</b></dt>
<dd>
Rotate the current selection 90 degrees clockwise (direction = 0) or
anticlockwise (direction = 1).
</dd>
</p>
<a name="evolve"></a><p><dt><b>g_evolve(<i>$cellarray, $numgens</i>)</b></dt>
<dd>
Advance the pattern in the given cell array reference by the specified
number of generations and return a reference to the new cell array.
</dd>
<dd> Example: <b>$newpatt = g_evolve($currpatt, 100);</b></dd>
</p>
<a name="join"></a><p><dt><b>g_join(<i>$cellarray1, $cellarray2</i>)</b></dt>
<dd>
Join the given cell arrays and return a reference to the resulting cell array.
If the given arrays are both one-state then the result is one-state.
If at least one of the given arrays is multi-state then the result is multi-state,
but with one exception: if both arrays have no cells then the result is
an empty one-state array. See <a href="#cellarrays">below</a>
for a description of one-state and multi-state cell arrays.
</dd>
<dd> Example: <b>$result = g_join($part1, $part2);</b></dd>
</p>
<a name="transform"></a><p><dt><b>g_transform(<i>$cellarray, $x0, $y0, $axx=1, $axy=0, $ayx=0, $ayy=1</i>)</b></dt>
<dd>
Apply an affine transformation to the pattern in the given cell array reference
and return a reference to the new cell array.
For each x,y cell in the input array the corresponding xn,yn cell in the output array
is calculated as xn = x0 + x*axx + y*axy, yn = y0 + x*ayx + y*ayy.
</dd>
<dd> Example: <b>$rot_blinker = g_transform($blinker, 0, 0, 0, -1, 1, 0);</b></dd>
</p>
<a name="parse"></a><p><dt><b>g_parse(<i>$string, $x0=0, $y0=0, $axx=1, $axy=0, $ayx=0, $ayy=1</i>)</b></dt>
<dd>
Parse an RLE or Life 1.05 string and return a reference to
an optionally transformed cell array.
</dd>
<dd> Example: <b>$blinker = g_parse("3o!");</b></dd>
</p>
<a name="putcells"></a><p><dt><b>g_putcells(<i>$cellarray, $x0=0, $y0=0, $axx=1, $axy=0, $ayx=0, $ayy=1, $mode="or"</i>)</b></dt>
<dd>
Paste the pattern in the given cell array reference into the current universe
using an optional affine transformation and optional mode ("and", "copy", "not", "or", "xor").
</dd>
<dd> Example: <b>g_putcells($cells, 6, -40, 1, 0, 0, 1, "xor");</b></dd>
</p>
<a name="getcells"></a><p><dt><b>g_getcells(<i>@rectarray</i>)</b></dt>
<dd>
Return any live cells in the specified rectangle as a cell array reference.
The given rectangle array can be empty (in which case the cell array is empty)
or it must represent a valid rectangle of the form (x,y,width,height).
</dd>
<dd> Example: <b>$cells = g_getcells( g_getrect() );</b></dd>
</p>
<a name="getclip"></a><p><dt><b>g_getclip()</b></dt>
<dd>
Parse the pattern data in the clipboard and return a cell array reference,
but where the first two numbers are the pattern's width and height
(not necessarily the minimal bounding box because the pattern might
have empty borders, or it might even be empty).
If the clipboard data is multi-state but all cell states happen to
be zero then the returned cell array is (wd,ht) rather than (wd,ht,0).
</dd>
<dd> Example: <b>$cells = g_getclip();</b></dd>
</p>
<a name="hash"></a><p><dt><b>g_hash(<i>@rectarray</i>)</b></dt>
<dd>
Return an integer hash value for the pattern in the given rectangle.
Two identical patterns will have the same hash value, regardless of their
location in the universe. This command provides a fast way to
detect pattern equality, but there is a tiny probability that two different
patterns will have the same hash value, so you might need to use additional
(slower) tests to check for true pattern equality.
</dd>
<dd> Example: <b>$h = g_hash( g_getrect() );</b></dd>
</p>
<a name="select"></a><p><dt><b>g_select(<i>@rectarray</i>)</b></dt>
<dd>
Create a selection if the given array represents a valid rectangle of the form
(x,y,width,height) or remove the current selection if the given array is empty.
</dd>
<dd> Example: <b>g_select(-10,-10,20,20);</b></dd>
</p>
<a name="getrect"></a><p><dt><b>g_getrect()</b></dt>
<dd>
Return the current pattern's bounding box as an array.
If there is no pattern then the array is empty, otherwise the
array is of the form (x,y,width,height).
</dd>
<dd> Example: <b>@pattrect = g_getrect();</b></dd>
</p>
<a name="getselrect"></a><p><dt><b>g_getselrect()</b></dt>
<dd>
Return the current selection rectangle as an array.
If there is no selection then the array is empty, otherwise the
array is of the form (x,y,width,height).
</dd>
<dd> Example: <b>@selrect = g_getselrect();</b></dd>
</p>
<a name="setcell"></a><p><dt><b>g_setcell(<i>$x, $y, $state</i>)</b></dt>
<dd>
Set the given cell to the specified state (0 for a dead cell, 1 for a live cell).
</dd>
</p>
<a name="getcell"></a><p><dt><b>g_getcell(<i>$x, $y</i>)</b></dt>
<dd>
Return the state of the given cell.
The following example inverts the state of the cell at 0,0.
</dd>
<dd> Example: <b>g_setcell(0, 0, 1 - g_getcell(0, 0));</b></dd>
</p>
<a name="setcursor"></a><p><dt><b>g_setcursor(<i>$string</i>)</b></dt>
<dd>
Set the current cursor according to the given string and return the old cursor string.
The given string must match one of the names in the Cursor Mode menu.
</dd>
<dd> Example: <b>$oldcurs = g_setcursor("Draw");</b></dd>
</p>
<a name="getcursor"></a><p><dt><b>g_getcursor()</b></dt>
<dd>
Return the current cursor as a string (ie. the ticked name in the Cursor Mode menu).
</dd>
</p>
<p><a name="control"></a> <br>
CONTROL COMMANDS
<a name="run"></a><p><dt><b>g_run(<i>$numgens</i>)</b></dt>
<dd>
Run the current pattern for the specified number of generations.
Intermediate generations are never displayed, and the final generation
is only displayed if the current <b>g_autoupdate</b> setting is 1.
</dd>
<dd> Example: <b>g_run(100);</b></dd>
</p>
<a name="step"></a><p><dt><b>g_step()</b></dt>
<dd>
Run the current pattern for the current step.
Intermediate generations are never displayed, and the final generation
is only displayed if the current <b>g_autoupdate</b> setting is 1.
</dd>
</p>
<a name="setstep"></a><p><dt><b>g_setstep(<i>$exp</i>)</b></dt>
<dd>
Temporarily set the current step exponent to the given integer.
A negative exponent sets the step size to 1 and also sets a delay between each
step, but that delay is ignored by the <b>g_run</b> and <b>g_step</b> commands.
Golly will reset the step exponent to 0 upon creating a new pattern,
loading a pattern file, or switching to a different algorithm.
</dd>
<dd> Example: <b>g_setstep(0);</b></dd>
</p>
<a name="getstep"></a><p><dt><b>g_getstep()</b></dt>
<dd>
Return the current step exponent.
</dd>
<dd> Example: <b>g_setstep( g_getstep() + 1 );</b></dd>
</p>
<a name="setbase"></a><p><dt><b>g_setbase(<i>$base</i>)</b></dt>
<dd>
Temporarily set the current base step to an integer from 2 to 10000.
Golly will restore the default base step
(set in <a href="prefs:control">Preferences > Control</a>) upon creating
a new pattern, loading a pattern file, or switching to a different algorithm.
</dd>
<dd> Example: <b>g_setbase(2);</b></dd>
</p>
<a name="getbase"></a><p><dt><b>g_getbase()</b></dt>
<dd>
Return the current base step.
</dd>
</p>
<a name="advance"></a><p><dt><b>g_advance(<i>$where, $numgens</i>)</b></dt>
<dd>
Advance inside (where = 0) or outside (where = 1) the current selection by the
specified number of generations. The generation count does not change.
</dd>
<dd> Example: <b>g_advance(0, 3);</b></dd>
</p>
<a name="reset"></a><p><dt><b>g_reset()</b></dt>
<dd>
Restore the starting pattern and generation count.
Also reset the algorithm, rule, scale, location and step exponent
to the values they had at the starting generation.
The starting generation is usually zero, but it can be larger after
loading an RLE/macrocell file that stores a non-zero generation count.
</dd>
</p>
<a name="setgen"></a><p><dt><b>g_setgen(<i>$gen</i>)</b></dt>
<dd>
Set the generation count using the given string.
Commas and other punctuation marks can be used to make a large number
more readable. Include a leading +/- sign to specify a number relative
to the current generation count.
</dd>
<dd> Example: <b>g_setgen("-1,000");</b></dd>
</p>
<a name="getgen"></a><p><dt><b>g_getgen(<i>$sepchar=""</i>)</b></dt>
<dd>
Return the current generation count as a string.
The optional parameter (default = "") specifies a separator
character that can be used to make the resulting string more readable.
For example, <b>g_getgen(",")</b> would return a string like "1,234,567"
but <b>g_getgen()</b> would return "1234567". Use the latter call if
you want to do arithmetic on the generation count.
</dd>
<dd> Example: <b>$gen = g_getgen();</b></dd>
</p>
<a name="getpop"></a><p><dt><b>g_getpop(<i>$sepchar=""</i>)</b></dt>
<dd>
Return the current population as a string.
The optional parameter (default = "") specifies a separator
character that can be used to make the resulting string more readable.
For example, <b>g_getpop(",")</b> would return a string like "1,234,567"
but <b>g_getpop()</b> would return "1234567". Use the latter call if
you want to do arithmetic on the population count.
</dd>
<dd> Example: <b>$pop = g_getpop();</b></dd>
</p>
<a name="empty"></a><p><dt><b>g_empty()</b></dt>
<dd>
Return 1 if the universe is empty or 0 if there is at least one live cell.
This is much more efficient than testing <b>getpop() == 0</b>.
</dd>
<dd> Example: <b>g_exit("All cells are dead.") if g_empty();</b></dd>
</p>
<a name="numstates"></a><p><dt><b>g_numstates()</b></dt>
<dd>
Return the number of cell states in the current universe. This will be a
number from 2 to 256, depending on the current algorithm and rule.
</dd>
<dd> Example: <b>$maxstate = g_numstates() - 1;</b></dd>
</p>
<a name="numalgos"></a><p><dt><b>g_numalgos()</b></dt>
<dd>
Return the number of algorithms (ie. the number of items in the Set Algorithm menu).
</dd>
<dd> Example: <b>$maxalgo = g_numalgos() - 1;</b></dd>
</p>
<a name="setalgo"></a><p><dt><b>g_setalgo(<i>$string</i>)</b></dt>
<dd>
Set the current algorithm according to the given string which must match
one of the names in the Set Algorithm menu.
</dd>
<dd> Example: <b>g_setalgo("HashLife");</b></dd>
</p>
<a name="getalgo"></a><p><dt><b>g_getalgo(<i>$index=current</i>)</b></dt>
<dd>
Return the algorithm name at the given index in the Set Algorithm menu,
or the current algorithm's name if no index is supplied.
</dd>
<dd> Example: <b>$lastalgo = g_getalgo( g_numalgos() - 1 );</b></dd>
</p>
<a name="setrule"></a><p><dt><b>g_setrule(<i>$string</i>)</b></dt>
<dd>
Set the current rule according to the given string.
If the current algorithm doesn't support the specified rule then
Golly will automatically switch to the first algorithm that does
support the rule. If no such algorithm can be found then you'll get
an error message and the script will be aborted.
</dd>
<dd> Example: <b>g_setrule("b3/s23");</b></dd>
</p>
<a name="getrule"></a><p><dt><b>g_getrule()</b></dt>
<dd>
Return the current rule as a string in canonical format.
</dd>
<dd> Example: <b>$oldrule = g_getrule();</b></dd>
</dd>
</p>
<p><a name="viewing"></a> <br>
VIEWING COMMANDS
<a name="setpos"></a><p><dt><b>g_setpos(<i>$x, $y</i>)</b></dt>
<dd>
Change the position of the viewport so the given cell is in the middle.
The x,y coordinates are given as strings so the viewport can be moved
to any location in the unbounded universe.
Commas and other punctuation marks can be used to make large numbers more readable.
Apart from a leading minus sign, most non-digits are simply ignored;
only alphabetic characters will cause an error message.
Note that positive y values increase downwards in Golly's coordinate system.
</dd>
<dd> Example: <b>g_setpos("1,000,000,000,000", "-123456");</b></dd>
</p>
<a name="getpos"></a><p><dt><b>g_getpos(<i>$sepchar=""</i>)</b></dt>
<dd>
Return the x,y position of the viewport's middle cell in the form
of a Perl array containing two strings.
The optional parameter (default = "") specifies a separator
character that can be used to make the resulting strings more readable.
For example, <b>g_getpos(",")</b> might return two strings like "1,234"
and "-5,678" but <b>g_getpos()</b> would return "1234" and "-5678".
Use the latter call if you want to do arithmetic on the x,y values.
</dd>
<dd> Example: <b>my ($x, $y) = g_getpos();</b></dd>
</p>
<a name="setmag"></a><p><dt><b>g_setmag(<i>$mag</i>)</b></dt>
<dd>
Set the magnification, where 0 corresponds to the scale 1:1, 1 = 1:2, -1 = 2:1, etc.
The maximum allowed magnification is 4 (= 1:16).
</dd>
<dd> Example: <b>g_setmag(0);</b></dd>
</p>
<a name="getmag"></a><p><dt><b>g_getmag()</b></dt>
<dd>
Return the current magnification.
</dd>
<dd> Example: <b>g_setmag( g_getmag() - 1 );</b></dd>
</p>
<a name="fit"></a><p><dt><b>g_fit()</b></dt>
<dd>
Fit the entire pattern in the viewport.
</dd>
</p>
<a name="fitsel"></a><p><dt><b>g_fitsel()</b></dt>
<dd>
Fit the current selection in the viewport.
The script aborts with an error message if there is no selection.
</dd>
</p>
<a name="visrect"></a><p><dt><b>g_visrect(<i>@rectarray</i>)</b></dt>
<dd>
Return 1 if the given rectangle is completely visible in the viewport.
The rectangle must be an array of the form (x,y,width,height).
</dd>
<dd> Example: <b>g_fitsel() if !g_visrect(@selrect);</b></dd>
</p>
<a name="autoupdate"></a><p><dt><b>g_autoupdate(<i>$bool</i>)</b></dt>
<dd>
When Golly runs a script this setting is initially 0.
If the given parameter is 1 then Golly will automatically update the
viewport and the status bar after each command that changes the
universe or viewport in some way. Useful for debugging Perl scripts.
</dd>
<dd> Example: <b>g_autoupdate(1);</b></dd>
</p>
<a name="update"></a><p><dt><b>g_update()</b></dt>
<dd>
Immediately update the viewport and the status bar, regardless of the
current <b>g_autoupdate</b> setting. Note that Golly always does an
update when a script finishes.
</dd>
</p>
<p><a name="layers"></a> <br>
LAYER COMMANDS
<a name="addlayer"></a><p><dt><b>g_addlayer()</b></dt>
<dd>
Add a new, empty layer immediately after the current layer and
return the new layer's index, an integer from 0 to <b>g_numlayers()</b> - 1.
The new layer becomes the current layer and inherits most of
the previous layer's settings, including its algorithm, rule, scale,
location, cursor mode, etc.
The step exponent is set to 0, there is no selection,
no origin offset, and the layer's initial name is "untitled".
</dd>
<dd> Example: <b>$newindex = g_addlayer();</b></dd>
</p>
<a name="clone"></a><p><dt><b>g_clone()</b></dt>
<dd>
Like <b>g_addlayer</b> (see above) but the new layer shares the
same universe as the current layer.
The current layer's settings are duplicated and most will be
kept synchronized so that a change to one clone automatically changes
all the others.
Each cloned layer does however have a separate viewport, so the same
pattern can be viewed at different scales and locations
(at the same time if layers are tiled).
</dd>
<dd> Example: <b>$cloneindex = g_clone();</b></dd>
</p>
<a name="duplicate"></a><p><dt><b>g_duplicate()</b></dt>
<dd>
Like <b>g_addlayer</b> (see above) but the new layer has a copy of the
current layer's pattern.
Also duplicates all the current settings but, unlike a cloned layer,
the settings are not kept synchronized.
</dd>
<dd> Example: <b>$dupeindex = g_duplicate();</b></dd>
</p>
<a name="dellayer"></a><p><dt><b>g_dellayer()</b></dt>
<dd>
Delete the current layer. The current layer changes to the previous
layer (unless layer 0 was deleted).
</dd>
</p>
<a name="movelayer"></a><p><dt><b>g_movelayer(<i>$fromindex, $toindex</i>)</b></dt>
<dd>
Move a specified layer to a new position in the layer sequence.
The chosen layer becomes the current layer.
</dd>
<dd> Example: <b>g_movelayer(1, 0);</b></dd>
</p>
<a name="setlayer"></a><p><dt><b>g_setlayer(<i>$index</i>)</b></dt>
<dd>
Set the current layer to the layer with the given index,
an integer from 0 to <b>g_numlayers()</b> - 1.
</dd>
<dd> Example: <b>g_setlayer(0);</b></dd>
</p>
<a name="getlayer"></a><p><dt><b>g_getlayer()</b></dt>
<dd>
Return the index of the current layer, an integer from 0 to <b>g_numlayers()</b> - 1.
</dd>
<dd> Example: <b>$currindex = g_getlayer();</b></dd>
</p>
<a name="numlayers"></a><p><dt><b>g_numlayers()</b></dt>
<dd>
Return the number of existing layers, an integer from 1 to <b>g_maxlayers()</b>.
</dd>
<dd> Example: <b>g_setoption("tilelayers",1) if g_numlayers() > 1;</b></dd>
</p>
<a name="maxlayers"></a><p><dt><b>g_maxlayers()</b></dt>
<dd>
Return the maximum number of layers (10 in this implementation).
</dd>
</p>
<a name="setname"></a><p><dt><b>g_setname(<i>$string, $index=current</i>)</b></dt>
<dd>
Set the name of the given layer, or the current layer's name
if no index is supplied.
</dd>
<dd> Example: <b>g_setname("temporary");</b></dd>
</p>
<a name="getname"></a><p><dt><b>g_getname(<i>$index=current</i>)</b></dt>
<dd>
Return the given layer's name, or the current layer's name
if no index is supplied.
</dd>
<dd> Example: <b>g_dellayer() if g_getname() eq "temporary";</b></dd>
</p>
<a name="setcolors"></a><p><dt><b>g_setcolors(<i>$colorarray</i>)</b></dt>
<dd>
Set the color(s) of one or more states in the current layer and its clones (if any).
If the given array contains a multiple of 4 integers then they are interpreted
as <i>state, red, green, blue</i> values.
A state value of -1 can be used to set all live states to the same color
(state 0 is <i>not</i> changed).
If the given array contains exactly 6 integers then they are interpreted
as a color gradient from <i>r1, g1, b1</i> to <i>r2, g2, b2</i>
for all the live states (state 0 is <i>not</i> changed).
If the given array is empty then all states (including state 0) are reset
to their default colors, depending on the current algorithm and rule.
Note that the color changes made by this command are only temporary.
Golly will restore the default colors if a new pattern is opened or created,
or if the algorithm or rule changes,
or if <a href="prefs:color">Preferences > Color</a> is used to change any
of the default colors/icons for the current layer's algorithm.
</dd>
<dd>
<table cellspacing=0 cellpadding=0>
<tr><td>Example: <b>g_setcolors([1,0,0,0, 2,0,0,0]);</b></td><td width=20>
</td><td># set states 1 and 2 to black</td></tr>
<tr><td>Example: <b>g_setcolors([-1,0,255,0]);</b></td><td width=20>
</td><td># set all live states to green</td></tr>
<tr><td>Example: <b>g_setcolors([255,0,0, 0,0,255]);</b></td><td width=20>
</td><td># live states vary from red to blue</td></tr>
<tr><td>Example: <b>g_setcolors([]);</b></td><td width=20>
</td><td># restore default colors</td></tr>
</table>
</dd>
</p>
<a name="getcolors"></a><p><dt><b>g_getcolors(<i>state=-1</i>)</b></dt>
<dd>
Return the color of a given state in the current layer as a reference to
an array of the form
</dd>
<p>
<dd><b>( state, red, green, blue )</b></dd>
<p>
<dd>
or if the given state is -1 (or not supplied) then return all colors as
</dd>
<p>
<dd><b>( 0, r0, g0, b0, . . . N, rN, gN, bN )</b></dd>
<p>
<dd>
where N equals <b>g_numstates()</b> - 1.
Note that the array reference returned by <b>g_getcolors</b> can be passed into
<b>g_setcolors</b>; this makes it easy to save and restore colors.
</dd>
<dd> Example: <b>$allcolors = g_getcolors();</b></dd>
<dd> Example: <b>$deadcolor = g_getcolors(0);</b></dd>
</p>
<p><a name="miscellaneous"></a> <br>
MISCELLANEOUS COMMANDS
<a name="setoption"></a><p><dt><b>g_setoption(<i>$name, $value</i>)</b></dt>
<dd>
Set the given option to the given value.
The old value is returned to make it easy to restore a setting.
Here are all the valid option names and their possible values:
</dd>
<p>
<dd>
<table cellspacing=0 cellpadding=0>
<tr><td><b>"autofit"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"boldspacing"</b></td><td width=20> </td><td>2 to 1000 (cells)</td></tr>
<tr><td><b>"drawingstate"</b></td><td width=20> </td><td>0 to g_numstates()-1</td></tr>
<tr><td><b>"fullscreen"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"hyperspeed"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"maxdelay"</b></td><td width=20> </td><td>0 to 5000 (millisecs)</td></tr>
<tr><td><b>"mindelay"</b></td><td width=20> </td><td>0 to 5000 (millisecs)</td></tr>
<tr><td><b>"opacity"</b></td><td width=20> </td><td>1 to 100 (percent)</td></tr>
<tr><td><b>"restoreview"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"savexrle"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showallstates"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showboldlines"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showeditbar"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showexact"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showgrid"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showhashinfo"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showlayerbar"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showpatterns"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showscripts"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showstatusbar"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"showtoolbar"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"stacklayers"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"swapcolors"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"switchlayers"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"synccursors"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"syncviews"</b></td><td width=20> </td><td>1 or 0</td></tr>
<tr><td><b>"tilelayers"</b></td><td width=20> </td><td>1 or 0</td></tr>
</table>
</dd>
<p>
<dd> Example: <b>$oldgrid = g_setoption("showgrid", 1);</b></dd>
</p>
<a name="getoption"></a><p><dt><b>g_getoption(<i>$name</i>)</b></dt>
<dd>
Return the current value of the given option.
See above for a list of all the valid option names.
</dd>
<dd> Example: <b>g_fit() if g_getoption("autofit");</b></dd>
</p>
<a name="setcolor"></a><p><dt><b>g_setcolor(<i>$name, $r, $g, $b</i>)</b></dt>
<dd>
Set the given color to the given RGB values (integers from 0 to 255).
The old RGB values are returned as an array of 3 integers to make it easy to restore the color.
Here is a list of all the valid color names and how they are used:
</dd>
<p>
<dd>
<table cellspacing=0 cellpadding=0>
<tr><td><b>"paste"</b></td><td width=20> </td><td>color for pasting patterns</td></tr>
<tr><td><b>"select"</b></td><td width=20> </td><td>color for selections (will be 50% transparent)</td></tr>
<tr><td><b><i>algoname</i></b></td><td width=20> </td><td>status bar background for given algorithm</td></tr>
</table>
</dd>
<p>
<dd> Example: <b>@oldrgb = g_setcolor("HashLife", 255, 255, 255);</b></dd>
</p>
<a name="getcolor"></a><p><dt><b>g_getcolor(<i>$name</i>)</b></dt>
<dd>
Return the current RGB values for the given color as an array of 3 integers.
See above for a list of all the valid color names.
</dd>
<dd> Example: <b>my ($r, $g, $b) = g_getcolor("select");</b></dd>
</p>
<a name="getclipstr"></a><p><dt><b>g_getclipstr()</b></dt>
<dd>
Return the current contents of the clipboard as an unmodified string.</dd>
<dd> Example: <b>$illegalRLE = g_getclipstr();</b></dd>
</p>
<a name="setclipstr"></a><p><dt><b>g_setclipstr(<i>$string</i>)</b></dt>
<dd>
Copy an arbitrary string (not necessarily a cell pattern) directly to the clipboard.</dd>
<dd> Example: <b>g_setclipstr($correctedRLE);</b></dd>
</p>
<a name="getstring"></a><p><dt><b>g_getstring(<i>$prompt, $initial="", $title=""</i>)</b></dt>
<dd>
Display a dialog box and get a string from the user.
If the initial string is supplied it will be shown and selected.
If the title string is supplied it will be used in the dialog's title bar.
The script will be aborted if the user hits the dialog's Cancel button.
</dd>
<dd> Example: <b>$i = g_getstring("Enter a number:", "100");</b></dd>
</p>
<a name="getkey"></a><p><dt><b>g_getkey()</b></dt>
<dd>
Return a key hit by the user as a single character,
or an empty string if no key was hit.
The characters returned by this command are a subset of ASCII:
</dd>
<p>
<dd>
<table cellspacing=0 cellpadding=0>
<tr><td><b>' '</b> to <b>'~'</b></td><td width=20> </td><td>all displayable characters (space to tilde)</td></tr>
<tr><td><b>chr(8)</b></td><td width=20> </td><td>backspace or delete</td></tr>
<tr><td><b>chr(9)</b></td><td width=20> </td><td>tab</td></tr>
<tr><td><b>chr(13)</b></td><td width=20> </td><td>return or enter</td></tr>
<tr><td><b>chr(28)</b> to <b>chr(31)</b></td><td width=20> </td><td>left, right, up, down arrows</td></tr>
</table>
</dd>
<p>
<dd> Example: <b>$ch = g_getkey();</b></dd>
</p>
<a name="dokey"></a><p><dt><b>g_dokey($char)</b></dt>
<dd>
This command allows limited keyboard interaction while a script is running.
The given character is passed to Golly's keyboard event handler, but all
keyboard shortcuts that can change the current pattern will be ignored.
</dd>
<dd> Example: <b>g_dokey( g_getkey() );</b></dd>
</p>
<a name="show"></a><p><dt><b>g_show(<i>$message</i>)</b></dt>
<dd>
Show the given string in the bottom line of the status bar.
The status bar is automatically shown if necessary.
</dd>
<dd> Example: <b>g_show("Hit any key to continue...");</b></dd>
</p>
<a name="error"></a><p><dt><b>g_error(<i>$message</i>)</b></dt>
<dd>
Beep and show the given string in the bottom line of the status bar.
The status bar is automatically shown if necessary.
</dd>
<dd> Example: <b>g_error("The pattern is empty.");</b></dd>
</p>
<a name="warn"></a><p><dt><b>g_warn(<i>$message</i>)</b></dt>
<dd>
Beep and show the given string in a modal warning dialog.
Useful for debugging Perl scripts or displaying error messages.
</dd>
<dd> Example: <b>g_warn("xxx = $xxx");</b></dd>
</p>
<a name="note"></a><p><dt><b>g_note(<i>$message</i>)</b></dt>
<dd>
Show the given string in a modal information dialog.
Useful for displaying multi-line results.
</dd>
<dd> Example: <b>g_note("Line 1\nLine 2\nLine 3");</b></dd>
</p>
<a name="help"></a><p><dt><b>g_help(<i>$htmlfile</i>)</b></dt>
<dd>
Open the given HTML file in the help window.
A non-absolute path is relative to the location of the script.
</dd>
<dd> Example: <b>g_help("results.html");</b></dd>
</p>
<a name="check"></a><p><dt><b>g_check(<i>$bool</i>)</b></dt>
<dd>
When Golly runs a script this setting is initially 1,
which means that event checking is enabled.
If the given parameter is 0 then event checking is disabled.
Typically used to prevent mouse clicks being seen at the wrong time.
This should only be done for short durations because the script
cannot be aborted while the setting is 0.
</dd>
<dd> Example: <b>g_check(0);</b></dd>
</p>
<a name="exit"></a><p><dt><b>g_exit(<i>$message=""</i>)</b></dt>
<dd>
Exit the script with an optional error message.
If a non-empty string is supplied then it will be displayed in the status bar
along with a beep, just like the <a href="#error"><b>g_error</b></a> command.
If no message is supplied, or if the string is empty, then there is no beep
and the current status bar message will not be changed.
</dd>
<dd> Example: <b>g_exit("There is no pattern.") if g_empty();</b></dd>
</p>
<p><a name="cellarrays"></a> <br>
<font size=+1><b>Cell arrays</b></font>
<p>
Some scripting commands manipulate patterns in the form of cell arrays.
Golly supports two types of cell arrays: one-state and multi-state.
A one-state cell array contains an even number of integers specifying
the x,y coordinates for a set of cells, all of which are assumed to
be in state 1:
<p>
<dd><b>( x1, y1, . . . xN, yN )</b></dd>
<p>
A multi-state cell array contains an odd number of integers specifying
the x,y,state values for a set of cells. If the number of cells is even
then a padding integer (zero) is added at the end of the array to ensure
the total number of integers is odd:
<p>
<dd><b>( x1, y1, state1, . . . xN, yN, stateN )</b> if N is odd</dd>
<dd><b>( x1, y1, state1, . . . xN, yN, stateN, 0 )</b> if N is even</dd>
<p>
All scripting commands that input cell arrays use the length of the
array to determine its type. When writing a script to handle multi-state
cell arrays you may need to allow for the padding integer, especially
if accessing cells within the array. See tile.pl for example.
<p>
Note that all scripting commands return <b>()</b> if the resulting
cell array has no cells. They never return <b>(0)</b>, although this
is a perfectly valid multi-state cell array and all commands can input
such an array. For example, <b>$newarray = g_join($array1,[0])</b>
can be used to convert a non-empty one-state array to multi-state.
<p>
One-state cell arrays are normally used in a two-state universe, but
they can also be used in a universe with more than two states.
A multi-state cell array can be used in a two-state universe, but
only if the array's cell states are 0 or 1.
<p>
The ordering of cells within either type of array doesn't matter.
Also note that positive y values increase downwards in Golly's
coordinate system.
<p>
Cell arrays can contain millions of integers, so all commands that accept
or return cell arrays actually use references to those arrays.
<p><a name="rectarrays"></a> <br>
<font size=+1><b>Rectangle arrays</b></font>
<p>
Some commands manipulate rectangles in the form of arrays.
An empty rectangle is indicated by an array with no items; ie. <b>()</b>.
A non-empty rectangle is indicated by an array containing four integers:
<p>
<dd><b>( left, top, width, height )</b></dd>
<p>
The first two items specify the cell at the top left corner of the
rectangle. The last two items specify the rectangle's size (in cells).
The width and height must be greater than zero.
<p>
Unlike cell arrays, rectangle arrays only contain a few items (0 or 4),
so all commands that accept or return rectangle arrays don't bother
using array references.
<p><a name="problems"></a> <br>
<font size=+1><b>Potential problems</b></font>
<p>
1.
Mac users need to ensure their Perl scripts use Unix line endings (LF).
If a script uses Mac line endings (CR) and the first line is a comment
then the Perl interpreter will treat the entire file as one long comment
and nothing will happen when the script is executed.
<p>
2.
The escape key check to abort a running script is not done by Perl but
by each Golly scripting command. This means that very long Perl computations
should call an occasional "no-op" command like <b>g_run(0)</b> to allow the
script to be aborted in a timely manner.
<p><a name="copyright"></a> <br>
<font size=+1><b>Perl copyright notice</b></font>
<p>
Golly uses an embedded Perl interpreter to execute scripts.
Perl is Copyright (C) 1993-2007, by Larry Wall and others.
It is free software; you can redistribute it and/or modify it under
the terms of either:
a) the GNU General Public License as published by the Free Software Foundation;
either version 1, or (at your option) any later version, or
b) the <a href="http://dev.perl.org/licenses/artistic.html">"Artistic License"</a>.
</body>
</html>
|