New TLE Community website using Eleventy. tlecommunity.com
site content wiki sample-script-examples-part-2.md
25 kB
Markdown
at main


title: 'Sample Script Examples, part 2' #

Sample Script Examples, part 2 #

updated:11/23/13

In this section, we’ll take a look at various examples for upgrading, sending ships, and building SS plans. As mentioned in my original Sample Script Examples post, I make no claims as to whether the methods I use are the best or not.

Upgrade_all is a Perl file that allows us to upgrade virtually any structure in the game. It has many options available (see Sample Script Commands in the Wiki). Its usage can be a bit tricky though. I’ve found it easier to use when upgrading the same buildings, even on several planets. However, when trying to upgrade multiple planets that have different buildings to upgrade, I’ve found it difficult to use. As it set’s a queue for upgrades, it causes subsequent instructions in a script to wait. So for example:

upgrade_all.pl --planet “One”--planet "Two"

upgrade_all.pl --planet “Three” --match “Algae Pond”

The first line of these instructions would upgrade buildings on planets One & Two, and then on line two only Algae Ponds on planet Three would be upgraded. But as upgrade_all.pl sets a build queue (up to 8 hours), if building takes less than 8 hours on either planet in the first line than the second line will have to wait for the timer on the queue to finish before it can be executed. While one could run multiple scripts to get around this issue, there is a simple way to disable the timer queue.

Using a text editor (like Notepad) open upgrade_all.pl. Near the beginning of the file, find the instruction: wait => 8 * 60 * 60,

Change this line to read: wait => 0 * 60 * 60,

By changing the eight to a zero, we have essentially disabled the queue function. Why we do this will become clearer in a moment. Using our modified upgrade_all.pl file, let’s see an example:

@echo off

cd c:\le\glc\examples

:start

FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B

FOR /F %%A IN ('TIME/T') DO SET Now=%%A

upgrade_all.pl --planet "One" --planet "Two" --match "Shipyard" --space

upgrade_all.pl --planet "Four" --match “Shield Against Weapons”

upgrade_all.pl --planet "Two" --planet “Three” --skip “Algae Pond” --skip “Apple Orchard”

echo Resuming in 1 hr from now: %Today% %Now%

perl -e "sleep 3600"

goto start

Here’s a file that loops back on itself, similar to examples from my first Sample Script Examples post.

In this example, we’re upgrading different buildings on multiple planets (lines 6-8), sleeping for 60 minutes (line 10), and then returning to the beginning to upgrade again. By using the Perl sleep function, we’re deciding how long the program sleeps or pauses before looping back around. That’s why we disabled the queue function in upgrade_all.pl

I’ve also added some MS-DOS instructions; line 4 sets the date (Today) and line 5 the time (Now) as variables that are used in line 9, which would display as such:

Resuming in 1 hr from now: 10/31/13 10:32

By displaying when the sleep cycle begins, we can tell when the timer will run out.

We could also modify the upgrade_all.pl timer, if desired. If you changed the timer queue to 1, for example: wait => 1 * 60 * 60,

This would max the queue timer at one hour.

Here are some examples we can use to send ships to other planets. So for example, if you wanted to send 100 fighters to defend another of your planets or space stations:

@echo off

cd c:\le\glc\examples

send_ships.pl --from " One" --type fighter --max 100 --planet "My SS"

send_ships.pl --from " Two" --type fighter --max 100 --planet "My SS"

send_ships.pl --from "Four" --type fighter --max 100 --planet "My SS"

We can only send fighters to defend another body, not sweepers. And to recall them:

@echo off

cd c:\le\glc\examples

recall_ships.pl --planet "One" --orbiting "My SS" --all

recall_ships.pl --planet "Two" --orbiting "My SS" --all

recall_ships.pl --planet "Three" --orbiting "My SS" –all

And to send 50 Fissure Sealers to seal a fissure on an uninhabited planet:

@echo off

cd c:\le\glc\examples

send_ships.pl --from "Four" --type fissure_sealer --planet "Oock 8" --max 50

Now let’s look at some scripts for building SS plans. This script goes through a series of loops to build nine lvl 5 warehouse plans, six lvl 6 warehouse plans and twelve lvl 7 warehouse plans. It can be modified to build any type or number of SS plans. NOTE: build times are dependent on several factors and your build times will be different. The Lacuna Expanse iPhone client specifies the build times beforehand, making it easy to insert the proper sleep times. This script incorporates concepts covered previously, so it’s pretty self explanatory. REM statements are included for documentation.

@echo off cd c:\le\glc\examples

set /a count=0

:LOOP1 REM In the first line, count=number of build cycles. Edit this number accordingly. REM When the variable “count” equals this value the program will skip to the next loop.

IF %count%==3 goto N2 set /a count+=1 ss_lab.pl --planet "One" --level 5 --type warehouse ss_lab.pl --planet "Three" --level 5 --type warehouse ss_lab.pl --planet "Four" --level 5 --type warehouse

REM The number of times the build cycle has gone around is displayed in the next line.

echo Building level 5 plans. Cycle %count%. Sleeping 3:51mins... perl -e "sleep 13860" goto LOOP1

:N2 REM The count is reset to 0 for a new build loop. set /a count=0

:LOOP2 IF %count%==2 goto N3 set /a count+=1 ss_lab.pl --planet "One" --level 6 --type warehouse ss_lab.pl --planet " Three" --level 6 --type warehouse ss_lab.pl --planet " Four" --level 6 --type warehouse echo Building level 6 plans. Cycle %count%. Sleeping 6:43mins... perl -e "sleep 24180" goto LOOP2

:N3 set /a count=0

:LOOP3 IF %count%==4 goto END set /a count+=1 ss_lab.pl --planet "One" --level 7 --type warehouse ss_lab.pl --planet "Three" --level 7 --type warehouse ss_lab.pl --planet "Four" --level 7 --type warehouse echo Building level 7 plans. Cycle %count%. Sleeping 11:45mins... perl -e "sleep 42300" goto LOOP3

:END

The above example could be modified in several ways. Still, it does require a fair bit of editing. Let’s look at another example that’s a little more sophisticated.

@echo off cd c:\le\glc\examples

set /a count=0

REM N=plan level

set /a N=5

:LOOP1 IF %count%==3 goto N2 set /a count+=1 ss_lab.pl --planet "One" --level %N% --type warehouse ss_lab.pl --planet "Three" --level %N% --type warehouse ss_lab.pl --planet "Four" --level %N% --type warehouse

REM The number of times the build cycle has gone around is displayed in the next line.

echo Building level 5 plans. Cycle %count%. Sleeping 3:51mins... perl -e "sleep 13860" goto LOOP1

:N2 REM The count is reset to 0 for a new build loop.

set /a count=0 set /a N=6

:LOOP2 IF %count%==2 goto N3 set /a count+=1 ss_lab.pl --planet "One" --level %N% --type warehouse ss_lab.pl --planet " Three" --level %N% --type warehouse ss_lab.pl --planet " Four" --level %N% --type warehouse echo Building level 6 plans. Cycle %count%. Sleeping 6:43mins... perl -e "sleep 24180" goto LOOP2

:N3 set /a count=0

:LOOP3

IF %count%==4 goto END set /a count+=1 set /a N=7 ss_lab.pl --planet "One" --level %N% --type warehouse ss_lab.pl --planet "Three" --level %N% --type warehouse ss_lab.pl --planet "Four" --level %N% --type warehouse echo Building level 7 plans. Cycle %count%. Sleeping 11:45mins... perl -e "sleep 42300" goto LOOP3

:END

See how we’ve used a variable to indicate the level number of the SS plans to be built. The variable N will be equal to the desired level for every line in a particular loop. Instead of editing the level number on several lines, we only need to edit it in one spot per loop.

Let’s look at another example of what we can do with variables:

@echo off cd c:\le\glc\examples

REM N=plan level

set /a N=3

REM name= plan name REM Valid plan names: art opera ibs command policestation parliament food

set name=art ss_lab.pl --planet "One" --level %N% --type %name% ss_lab.pl --planet "Three" --level %N% --type %name% ss_lab.pl --planet "Four" --level %N% --type %name% ss_lab.pl --planet "Five" --level %N% --type %name% ss_lab.pl --planet "Six" --level %N% --type %name% echo Building SS %name% plans level %N%

:END

In the above simple example, we’re building SS plans on several planets. It is necessary to set the plan name and level only once, using the variables N and name. In this example, we’re building 5 Art Museum plans of level 3. As we’re only building one set of plans, we not interested in performing any loops, so don’t need to sleep.

We could modify the above script to perform several loops, by incorporating loops as illustrated in the previous example. However, we’d still need to edit the Perl sleep command to the correct amount of time depending on the level plan we wished to build.

Here is an example of a fully automated SS plans menu. It will accept input for the plan type and level desired, and confirms that is what you wish to build before proceeding. SS levels 1-10 are the only options.

Copy and paste this example into a file and call it SS menu.bat. Simply modify the planet names in the build menu to match the names of your planets with SS labs. REM statements are included for documentation.

@echo off cd c:\le\glc\examples

REM :start - the main menu subroutine, where plan type is selected REM cls - clears the screen REM echo. - skips a space

:start cls echo. echo SELECT SPACE STATION PLAN echo --------------------------------- echo. echo 1 - Build Art Museum Plans echo 2 - Build Culinary Institute Plans echo 3 - Build Interstellar Broadcast System Plans echo 4 - Build Opera House Plans echo 5 - Build Parliament Plans echo 6 - Build Police Station Plans echo 7 - Build Station Command Center Plans echo 8 - Build Warehouse Plans echo 9 - Exit echo.

REM The next line displays valid options and accepts an input.

set /p opt1=Enter option 1 2 3 4 5 6 7 8 or 9:

REM input is set as a variable "opt1" REM IF statement checks the value of "opt1"

if "%opt1%"=="1" set var=art& goto level if "%opt1%"=="2" set var=food& goto level if "%opt1%"=="3" set var=ibs& goto level if "%opt1%"=="4" set var=opera& goto level if "%opt1%"=="5" set var=parliament& goto level if "%opt1%"=="6" set var=policestation& goto level if "%opt1%"=="7" set var=command& goto level if "%opt1%"=="8" set var=warehouse& goto level if "%opt1%"=="9" goto exit goto start

REM Depending on the value of "opt1", each option sets a variable "var" to the appropriate SS plan name. REM The ampersand allows a second instruction to be executed after setting "var", in this case, branching to the level menu. REM Entering a 9 will cause the program to terminate. REM goto start - branches back to the main menu if an invalid entry is encountered. REM :level - the level menu subroutine, where plan level is selected

:level cls echo.

REM echo %var% plan selected - displays selected SS plan name, eg: art plan selected

echo %var% plan selected echo. echo SELECT SPACE STATION LEVEL echo ---------------------------------- echo Enter a value between 1 and 10: echo 0 - Return to Main Menu echo.

REM The next line accepts an input. Similar to the option found in the main menu, but doesn't display any options .

set /p opt2=Enter option:

REM input is set as a variable "opt2" REM IF statement checks the value of "opt2"

if "%opt2%"=="1" set /a lvl=1& goto confirm if "%opt2%"=="2" set /a lvl=2& goto confirm if "%opt2%"=="3" set /a lvl=3& goto confirm if "%opt2%"=="4" set /a lvl=4& goto confirm if "%opt2%"=="5" set /a lvl=5& goto confirm if "%opt2%"=="6" set /a lvl=6& goto confirm if "%opt2%"=="7" set /a lvl=7& goto confirm if "%opt2%"=="8" set /a lvl=8& goto confirm if "%opt2%"=="9" set /a lvl=9& goto confirm if "%opt2%"=="10" set /a lvl=10& goto confirm if "%opt2%"=="0" goto start goto level

REM Depending on the value of "opt2", each option sets a variable "lvl" to the appropriate SS plan level. REM The ampersand allows a second instruction to be executed after setting "lvl", in this case, REM branching to the confirm menu. REM Entering a 0 will branch back to main menu. REM goto level - branches back to the level menu if invalid entry is encountered. REM :confirm - the confirm menu subroutine, where confirmation of menu options occurs. REM Not a necessary function, can be skipped. In the level menu, replace each: goto confirm with: goto build to bypass. Delete cancel menu subroutine.

:confirm echo.

REM echo Ready to build SS %var% plans level %lvl% - displays selected SS plan name and level, REM eg: Ready to build SS art plans level 3

echo Ready to build SS %var% plans level %lvl% echo.

REM The next line displays valid options and accepts an input.

set /p confirmDeploy=Confirm deployment of code [y/n] ?:

REM /I option ignores upper and lower case, so Y,y,N,n are all valid options. REM Depending on the value of "confirmDeploy", branches to build menu or cancel menu. REM If invalid option is encounted, "Invalid response" displayed and returns to confirm menu.

if /I "%confirmDeploy%"=="y" goto build if /I "%confirmDeploy%"=="n" goto cancel echo. echo Invalid response goto confirm

REM :build - build menu subroutine. Where Perl instruction build SS plans. REM In this example, every planet that has a SS lab (that can build up to level 10 SS plans) has been included. Branches to end menu where program terminates.

:build echo. echo Building SS %var% plans level %lvl% ss_lab.pl --planet "One" --level %lvl% --type %var% ss_lab.pl --planet "Three" --level %lvl% --type %var% ss_lab.pl --planet "Four" --level %lvl% --type %var% ss_lab.pl --planet "Five" --level %lvl% --type %var% ss_lab.pl --planet "Six" --level %lvl% --type %var% goto end

REM :cancel - cancel menu subroutine. Build aborted. Perl sleep command utilized so message can be displayed for a moment before returning to main menu.

:cancel echo. echo Build cancelled, returning to Main Menu... perl -e "sleep 2" goto start

REM :end - end menu subroutine. Program terminates after this point.

:end

In my first Sample Script Examples post, I offered an example of a batch file that could build several ship types on a single colony. Here's an updated version of that script which offers the user the options of colony, ship types and number of ships to build. The script is written to compensate for the possibility that not every colony can build every ship type. It also checks for the maximum number of queues available to compensate for varying number of shipyards/shipyard leveles per colony. To keep it from getting too complex, I've excluded most of the optional arguments in build_ships.pl except for --noreserve. The script builds upon previous examples and uses variables extensively to cut down on repetative typing. It can be modified to accomodate any number of colonies and ship types. Here is Ship_Building_Menu.bat:

@echo off cd c:\le\glc\examples

:mainmenu cls echo. echo Select a Ship Building Colony echo ----------------------------- echo. echo 1 - Planet 1 echo 2 - Planet 2 echo 3 - Planet 3 echo 0 - Exit echo.

REM max=maximum number of ships in your build queue for the shipyards on a colony. This is a user defined entry.

set /p place=Enter option 1 2 3 or 0: if "%place%"=="1" set planet=Planet 1& set /a max=120& goto ship1 if "%place%"=="2" set planet=Planet 2& set /a max=100& goto ship2 if "%place%"=="3" set planet=Planet 3& set /a max=80& goto ship3 if "%place%"=="0" goto exit goto mainmenu

REM sets max # of ships that can be queued for a colony & branches to subroutine ship1, ship2 or ship3 depending on colony selected.

:ship1 cls set /a option=0 echo. echo Select Option for %planet% echo ------------------------------ echo. echo 1 - Build Fighters echo 2 - Build Snark 3's echo 3 - Build Sweepers echo 4 - Build Excavators echo 5 - Build Gas Giant Settlement Ships echo 6 - Build Mega Scows echo 7 - Build Huge Hulks echo 8 - Build Smuggler Ships echo 9 - Build Spy Pods echo 10 - Build Space Station Hull echo 11 - Build Spaceport Seekers echo 12 - Build Security Ministry Seekers echo 13 - Build Observatory Seekers echo 14 - Build Fissure Sealers echo. echo Press Enter to return to Main Menu echo.

REM get ship names from build_ships.pl

set /p option=Enter option: if "%option%"=="0" goto mainmenu if "%option%"=="1" set type=fighter& goto quantity if "%option%"=="2" set type=snark3& goto quantity if "%option%"=="3" set type=sweeper& goto quantity if "%option%"=="4" set type=excavator& goto quantity if "%option%"=="5" set type=gas_giant_settlement_ship& goto quantity if "%option%"=="6" set type=scow_mega& goto quantity if "%option%"=="7" set type=hulk_huge& goto quantity if "%option%"=="8" set type=smuggler_ship& goto quantity if "%option%"=="9" set type=spy_pod& goto quantity if "%option%"=="10" set type=space_station& goto quantity if "%option%"=="11" set type=spaceport_seeker& goto quantity if "%option%"=="12" set type=security_ministry_seeker& goto quantity if "%option%"=="13" set type=observatory_seeker& goto quantity if "%option%"=="14" set type=fissure_sealer& goto quantity goto ship1

:ship2 cls set /a option=0 echo. echo Select Option for %planet% echo ------------------------------ echo. echo 1 - Build Fighters echo 2 - Build Snark 3's echo 3 - Build Sweepers echo 4 - Build Excavators echo 5 - Build Mega Scows echo 6 - Build Huge Hulks echo 7 - Build Smuggler Ships echo 8 - Build Spy Pods echo 9 - Build Spaceport Seekers echo 10 - Build Security Ministry Seekers echo 11 - Build Observatory Seekers echo 12 - Build Fissure Sealers echo. echo Press Enter to return to Main Menu echo. set /p option=Enter option: if "%option%"=="0" goto mainmenu if "%option%"=="1" set type=fighter& goto quantity if "%option%"=="2" set type=snark3& goto quantity if "%option%"=="3" set type=sweeper& goto quantity if "%option%"=="4" set type=excavator& goto quantity if "%option%"=="5" set type=scow_mega& goto quantity if "%option%"=="6" set type=hulk_huge& goto quantity if "%option%"=="7" set type=smuggler_ship& goto quantity if "%option%"=="8" set type=spy_pod& goto quantity if "%option%"=="9" set type=spaceport_seeker& goto quantity if "%option%"=="10" set type=security_ministry_seeker& goto quantity if "%option%"=="11" set type=observatory_seeker& goto quantity if "%option%"=="12" set type=fissure_sealer& goto quantity goto ship2

:ship3 cls set /a option=0 echo. echo Select Option for %planet% echo ------------------------- echo. echo 1 - Build Fighters echo 2 - Build Snark 3's echo 3 - Build Sweepers echo 4 - Build Excavators echo 5 - Build Mega Scows echo 6 - Build Huge Hulks echo 7 - Build Smuggler Ships echo 8 - Build Spaceport Seekers echo 9 - Build Security Ministry Seekers echo 10 - Build Observatory Seekers echo 11 - Build Fissure Sealers echo. echo Press Enter to return to Main Menu echo. set /p option=Enter option: if "%option%"=="0" goto mainmenu if "%option%"=="1" set type=fighter& goto quantity if "%option%"=="2" set type=snark3& goto quantity if "%option%"=="3" set type=sweeper& goto quantity if "%option%"=="4" set type=excavator& goto quantity if "%option%"=="5" set type=scow_mega& goto quantity if "%option%"=="6" set type=hulk_huge& goto quantity if "%option%"=="7" set type=smuggler_ship& goto quantity if "%option%"=="8" set type=spaceport_seeker& goto quantity if "%option%"=="9" set type=security_ministry_seeker& goto quantity if "%option%"=="10" set type=observatory_seeker& goto quantity if "%option%"=="11" set type=fissure_sealer& goto quantity goto ship3

:quantity cls set /a number=0 echo. echo You selected building %type%s on %planet%. echo. echo Select Number of Ships to Build ECHO ------------------------------- ECHO Enter a value between 1 and %max% echo. echo Press Enter to return to Main Menu echo.

REM max=maximum number of ships in your build queue for the shipyards on a colony. User defined in main menu subroutine.

REM EQU - equal NEQ - not equal LSS - less than LEQ - less than or equal GTR - greater than GEQ - greater than or equal

set /p number=Enter number of ships to build: IF %number% EQU 0 goto mainmenu IF %number% LSS 0 echo Invalid Input & perl -e "sleep 1" & goto quantity IF %number% GTR %max% echo Invalid Input & perl -e "sleep 1" & goto quantity goto confirm

:confirm echo. echo Ready to build %number% %type%s on %planet% echo. set /p confirmbuild=Confirm deployment of code [y/n] ?: if /I "%confirmbuild%"=="y" goto build if /I "%confirmbuild%"=="n" goto cancel echo. echo Invalid response goto confirm

:cancel echo. echo Build cancelled, returning to Main Menu... perl -e "sleep 1" goto mainmenu

:build build_ships.pl --yards shipyard.js --type %type% --number %number% --noreserve --planet "%planet%" echo Returing to Main Menu perl -e "sleep 3" goto mainmenu

:exit

That’s all for now. Again, 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