--- title: 'Sample Script Examples' --- # Sample Script Examples Updated: 11/23/13 Okay then, you’ve installed Perl, set up the Lacuna Game Client, and now you’re ready to start scripting. But what exactly does that mean? There are [sample script commands](/wiki/sample-script-commands/) in the Wiki, but how exactly can they be used to script? You could type each command in a DOS window, but that would be tedious and time consuming. It’d be much easier to create a batch file to do that. That way, you could string together multiple commands or instructions and do several things at once. The example [scripts](/wiki/scripts/) presented here are geared toward the casual user whose scripting needs are simple. They should give you some idea of what’s possible and what you may be able to accomplish. I make no claims as to whether these examples are the best or easiest way to script. They should work on a Windows 7 PC. I use MS DOS because I’m familiar with it and it’s relatively easy. Other programming languages are going to be more powerful. If you’re interesting in learning more about MS DOS commands, a good starting point is: [http://www.computerhope.com/msdos.htm](http://www.computerhope.com/msdos.htm) Let’s start off with some examples. Using a text editor, like notepad, we create a simple batch file: docked.bat. It’s just like writing a text file, except we use the extension .bat instead of .txt. These are the contents of docked.bat: @echo off cd c:\\le\\glc\\examples perl docked\_[ships](/wiki/ships/).pl pause Our first line: @echo off, is used to prevent each subsequent line from echoing or printing to the screen. If you really want to see each line on screen as the script runs, you can omit this instruction. On line two, we’re pointing to the direction where Perl can find the file docked\_[ships](/wiki/ships/).pl. .pl means it’s a perl file. cd stands for “change directory”. The file docked.pl can be found on the C drive in directory le->glc->examples. If your perl files where located on drive D in directory lacuna->data->perl, then your line two would read: cd d:\\lacuna\\data\\perl Line three is the actual perl command which uses the perl file docked.pl to list all docked [ships](/wiki/ships/) on every colony you have. Note: you don’t necessarily have to preface commands with ‘perl’. Docked.pl should run ok by itself if you’ve set up Perl correctly on your system. If for some reason you’re having difficulty, then include perl before the command. The last line, pause , prevents the batch file from ending until you press a key. This way, we can view the list. Otherwise, the batch file would terminate and the list would disappear. When I want to run docked.bat, I use my file manager to locate that file on my hard drive and double click it. That’s the simplest way to use it. You don’t need to be logged in to the game to run it. If you wanted to automate your scripting, say, so you could run certain [scripts](/wiki/scripts/) everyday at a certain time, then you could use Windows Task Scheduler to run your batch files. But that’s beyond the scope of this tutorial. Ok, let’s look at another example. This file will be called upgrade.bat: @echo off cd c:\\le\\glc\\examples upgrade\_all.pl --planet "My Planet 1" --planet "My Planet 2" --match [Shipyard](/wiki/shipyard/) The first two lines are the same as in the previous example. The third line uses the file upgrade\_all.pl to upgrade [buildings](/wiki/buildings/) on two of our planets. If we use the [Sample Script Commands](/wiki/sample-script-commands/) page in the Wiki to look up the options for this file, this is what we find: Options: --help - This info. --verbose - Print out more information --config FILE - Specify a GLC config file, normally lacuna.yml --planet NAME - Specify planet --dumpfile FILE - data dump for all the info we don't print --maxlevel INT - do not upgrade if this level has been achieved --maxnum INT - Use this if lower than dev ministry level --maxadd INT - Add at most INT [buildings](/wiki/buildings/) to the queue per pass --wait INT - Max number of seconds to wait to repeat loop --sleep INT - Pause between RPC calls. Default 1 --junk - Upgrade Junk [Buildings](/wiki/buildings/) --[glyph](/wiki/glyph/) - Upgrade [Glyph](/wiki/glyph/) [Buildings](/wiki/buildings/) --space - Upgrade spaceports --city - Upgrade LCOT --lab - Upgrade labs --match STRING - Only upgrade matching building names --skip STRING - Skip building names (multiple allowed) --extra STRING - Add matching names to usual list to upgrade --dry - Do not actually upgrade In our example, we used the --planet NAME option twice. Some perl files may only allow you to use it once. Note that spacing is important. Also, spelling has to be exact and is case sensitive. The option --match allows us to specify a specific building and could also be used multiple times to specify multiple [buildings](/wiki/buildings/). So line three is only upgrading [shipyard](/wiki/shipyard/)s. If we wanted to upgrade different [buildings](/wiki/buildings/) on other planets, we could add a fourth line, for example: upgrade\_all.pl --planet "My Planet 3" --skip [Space Port](/wiki/space-port/) This last line would upgrade all [buildings](/wiki/buildings/) on that planet except the [space port](/wiki/space-port/)s. You can string together multiple lines of commands to perform many tasks in the game which is much easier than clicking on [buildings](/wiki/buildings/) on different planets. Now let’s take a look at a script that builds [ships](/wiki/ships/). We’ll call this file [fighter](/wiki/fighter/)s.bat: @echo off cd c:\\le\\glc\\examples build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [fighter](/wiki/fighter/) --number 50 --planet "My Planet 1" On our colony My Planet 1, we have two level 30 [shipyard](/wiki/shipyard/)s. We want to build 50 [fighter](/wiki/fighter/)s, though we could build a maximum of 60 [ships](/wiki/ships/) at a time (1 per level of each [shipyard](/wiki/shipyard/)). [Shipyard](/wiki/shipyard/)s.js is the file that stores info on the state of the [shipyard](/wiki/shipyard/)s on all your planets. It’s important to keep this file up to date if you’ve upgraded your [shipyard](/wiki/shipyard/)s. To do that, we can use the following command found on the [Sample Script Commands](/wiki/sample-script-commands/) page in the Wiki: get\_[buildings](/wiki/buildings/).pl –config../ lacuna.yml --[shipyard](/wiki/shipyard/) --shipfile [shipyard](/wiki/shipyard/)s--[shipyard](/wiki/shipyard/)s.js You could type this line at the DOS (command) prompt, but it’s much easier to use it in a batch file: @echo off cd c:\\le\\glc\\examples get\_[buildings](/wiki/buildings/).pl --[shipyard](/wiki/shipyard/) --shipfile [shipyard](/wiki/shipyard/)s.js Notice I’ve altered the command. I’ve trimmed it down to just what’s required for it to run. Your [stats](/wiki/stats/) and [shipyard](/wiki/shipyard/) levels will determine how long it will take to build those [fighter](/wiki/fighter/)s. Now let’s say you want to build lots of [ships](/wiki/ships/). Assuming you have two level 30 [shipyard](/wiki/shipyard/)s on your planet, and that 60 [sweeper](/wiki/sweeper/)s would take 40 minutes to finish building. You could just keep rerunning the script every 40 minutes or so. Surely there must be some better ways available. Let’s take a look at some options: @echo off cd c:\\le\\glc\\examples build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [sweeper](/wiki/sweeper/) --number 60 --noreserve --planet "My Planet 1" echo sleeping for 40 mins... perl -e "sleep 2400" build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [sweeper](/wiki/sweeper/) --number 60 --noreserve --planet "My Planet 1" echo sleeping for 40 mins... perl -e "sleep 2400" In the above example, we’re using the perl sleep command to pause the batch file for 40 minutes. 40 minutes x 60sec’s=2400 sec’s. We also used the echo command to echo a message to the screen to remind us of what’s going on. Then we repeated the same instruction. We also added --noreserve to our build [ships](/wiki/ships/) instruction. This causes the instruction to ignore the reserve number in the datafile and ensures we build the maximum number of [ships](/wiki/ships/) on each [shipyard](/wiki/shipyard/). We could repeat the building instructions in this way several times and build lots of [ships](/wiki/ships/). But there are better ways that require less typing: @echo off cd c:\\le\\glc\\examples set /a count=0 :LOOP set /a count+=1 build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [sweeper](/wiki/sweeper/) --number 60 --noreserve --planet " My Planet 1" REM the number in the next line equals the number of building cycles IF %count%==10 goto END echo Building [sweeper](/wiki/sweeper/)s. Cycle %count% of 10. Sleeping for 40 mins... perl -e "sleep 2400" goto :LOOP :END This batch file is using a loop to count the number of ship building cycles that we want. Let’s take a closer look at it. In line 3, we’re setting a variable which we’re going to call ‘count’ to zero. You could call it whatever you wanted: counter, number1, N, etc. Line 4 is where our loop begins. :LOOP is the name of the target label which represents a particular point in our program where we want come back to later on. As with the variable ‘count’, you can name your labels whatever you want, as long as it begins with a colon. Line 5 is where we use the SET command to increase the value of ‘count’ by 1. Line 6 is the instruction we’ve already seen for building our [sweeper](/wiki/sweeper/)s. Line 7 has a REM statement, which is a way to record remarks inside the body of a batch file. The comments which come after REM remind us of something and are not displayed on the screen. On line 8, we’re using the conditional command IF to determine if the variable ‘count’ is equal to 10. If it is, then the GOTO command instructs our program to skip to the target label called END. If ‘count’ is not =10, then the sequence continues onto the next line. Line 9 echo’s a reminder as to which build cycle we’re currently on by displaying the current value of ‘count’. Every time the program goes thru the loop we’ve set up, the value of ‘count’ will increment by one, and that increase is what will be indicated here. Line 10, as we’ve already seen, pauses the program for enough time to allow building to finish. Line 11 sends the program back to up to :LOOP to repeat the process. The last line is the target label :END. As there are no instructions after this point, the program will end. So in this example, ship building will cycle ten times, and on the tenth cycle it will end. On the last cycle, I saw no need to pause or sleep, so the program ends before the last batch of [ships](/wiki/ships/) are finished building. If I wanted the program to end when the last batch of [ships](/wiki/ships/) were done, I could rearrange the commands like so: @echo off cd c:\\le\\glc\\examples set /a count=0 :LOOP IF %count%==10 goto END set /a count+=1 build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [sweeper](/wiki/sweeper/) --number 60 --noreserve --planet " My Planet 1" IF %count%==10 goto END echo Building [sweeper](/wiki/sweeper/)s. Cycle %count% of 10. Sleeping for 40 mins... perl -e "sleep 2400" goto :LOOP :END Notice I moved “set /a count+=1”. Now the program will have to loop back around one last time in order to check if ‘count’ has reached 10. I could have also counted down instead of up. I would have had to set the counter initially to 10: set/a count=10 Subtract instead of add 1: set /a count-=1 And ended the program at zero instead of ten: if %count%==0 goto end It’s just a matter of preference. Here’s an example of a more complex batch file that offers a choice of several [ships](/wiki/ships/) we can build: @echo off cd c:\\le\\glc\\examples echo. echo SELECT OPTION FOR My Planet 1 echo ----------------------------- echo. :menu echo 1- Build [Fighter](/wiki/fighter/)s echo 2- Build [Snark](/wiki/snark/)'s echo 3- Build [Sweeper](/wiki/sweeper/)s echo 4- Exit echo. set /p option=enter option 1 2 3 or 4: if "%option%"=="1" goto createftr if "%option%"=="2" goto createsnrk if "%option%"=="3" goto createsweep if "%option%"=="4" goto exit :createftr build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [fighter](/wiki/fighter/) --number 60 --noreserve --planet " My Planet 1" goto exit :createsnrk build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [snark](/wiki/snark/) --number 60 --noreserve --planet " My Planet 1" goto exit :createsweep build\_[ships](/wiki/ships/).pl --yards [shipyard](/wiki/shipyard/)s.js --type [sweeper](/wiki/sweeper/) --number 60 --noreserve --planet " My Planet 1" goto exit :exit As you can see, I can select which ship I want to build. I could add the same kind of loops we saw in the last example and build lots of [ships](/wiki/ships/). I could add many more options too. Now let’s tie several perl commands together and look at a script that you might run once a day. We’ll call this batch file daily.bat: @echo off cd c:\\le\\glc\\examples spy\_run.pl --from "My [Capitol](/wiki/capitol/)" --target "My [Capitol](/wiki/capitol/)" --number 1 --task [Security Sweep](/wiki/security-sweep/) spy\_run.pl --from " My Planet 2" --target "My Planet 2" --number 1 --task [Security Sweep](/wiki/security-sweep/) spy\_run.pl --from " My Planet 3" --target "My Planet 3" --number 1 --task [Security Sweep](/wiki/security-sweep/) push\_[glyph](/wiki/glyph/)s.pl --from "My Planet 2" --to "My [Capitol](/wiki/capitol/)" --ship "[Galleon](/wiki/galleon/)" push\_[glyph](/wiki/glyph/)s.pl --from "My Planet 3" --to "My [Capitol](/wiki/capitol/)" --ship "[Galleon](/wiki/galleon/)" push\_[plans](/wiki/plans/).pl --from "My Planet 2" --to "My [Capitol](/wiki/capitol/)" --ship "[Hulk](/wiki/hulk/)" push\_[plans](/wiki/plans/).pl --from "My Planet 3" --to "My [Capitol](/wiki/capitol/)" --ship "[Hulk](/wiki/hulk/)" echo Pausing for 3 minutes... perl -e "sleep 180" assemble\_halls.pl --planet "My [Capitol](/wiki/capitol/)" --use-last send\_[ships](/wiki/ships/).pl --type [scow](/wiki/scow/)\_mega --from "My [Capitol](/wiki/capitol/)" --own-star send\_[ships](/wiki/ships/).pl --type [scow](/wiki/scow/)\_mega --from "My Planet 2" --own-star send\_[ships](/wiki/ships/).pl --type [scow](/wiki/scow/)\_large --from "My Planet 3" --own-star call buildexcavators.bat [waste](/wiki/waste/)\_chain.pl --planet "My [Capitol](/wiki/capitol/)” --equalize [waste](/wiki/waste/)\_chain.pl --planet "My Planet 1" --equalize [waste](/wiki/waste/)\_chain.pl --planet "My Planet 2" --equalize Lines 3-5: We’re doing a [security sweep](/wiki/security-sweep/) on every planet in our empire. I want only one spy on each planet to perform this task. Lines 6-7: pushing all [glyph](/wiki/glyph/)s from our planets to our [capitol](/wiki/capitol/) planet. If I don’t select a particular ship type, then one will be selected automatically. I’ve selected a ship which is large enough to move the [glyph](/wiki/glyph/)s we get on a daily basis. Smaller [ships](/wiki/ships/) tend to be faster than larger ones. Lines 8-9: pushing all [plans](/wiki/plans/) from our planets to our [capitol](/wiki/capitol/) planet. As above, I’ve selected a particular ship type. Lines 10-11: pausing to allow the shipped goods to arrive at our [capitol](/wiki/capitol/) planet (based on the speeds of the selected [ships](/wiki/ships/) and the distance from sending planets to the receiving one). Line 12: turn our [glyph](/wiki/glyph/)s into Halls in the [Excavator](/wiki/excavator/) Ministry, using the last of any [glyph](/wiki/glyph/) if necessary to build a hall plan. Lines 13-15: dispose of [waste](/wiki/waste/) on all our planets. Note that ship type: [scow](/wiki/scow/), [scow](/wiki/scow/)\_large, [scow](/wiki/scow/)\_fast or [scow](/wiki/scow/)\_mega must be specified. In this example, the amount of [waste](/wiki/waste/) actually removed will depend on the amount on hand and the capacity and number of [scow](/wiki/scow/)s available. Line 16: Uses the Call statement to call another batch file within a batch file. In this example, we’re transferring to another batch file (buildexcavators.bat) without aborting the execution of the calling batch file (daily.bat). Once buildexcavators.bat finishes, daily.bat will pick up where it left off and continue to the next line of instruction. Using this technique can be useful in so far as several small batch files can be easier to troubleshoot or modify than one large one. Lines 17-19: Equalizes the [waste](/wiki/waste/) production on all our planets so that [waste](/wiki/waste/) production will be zero. This is a function found in the [trade ministry](/wiki/trade-ministry/). Note that if you don’t have enough [scow](/wiki/scow/)s assigned to a [waste chain](/wiki/waste-chain/), or are producing more [waste](/wiki/waste/) than the assigned [ships](/wiki/ships/) can carry, then some [waste](/wiki/waste/) will be continue to be produced. I hope these examples have given you some ideas as to what you can do to make tasks easier and automated in the game. Happy scripting! \-Frobozz