New TLE Community website using Eleventy. tlecommunity.com
site content wiki scripting-by-garloo.md
8.2 kB
Markdown
at main


title: 'Scripting - By Garloo' #

Scripting - By Garloo #

Article submitted by Garloo

Greetings! My name is Garloo, and I recently installed Perl and started using scripts to enhance my game time in The Lacuna Expanse. I was more than a little hesitant at first, not knowing Perl and having no programming experience. However, United Federation was kind enough to help me and got me set up and running simple scripts. Without his patient tutoring, I would have given up before I even got started. Now that I have a basic understanding of scripting, it’s not as bad as I thought it would be. I thought it would be nice to share that experience, and decided to write an article about it to help beginners like me. This is not meant to replace or supersede the guide for installation of Perl for Windows found on UF’s website, just to supplement it. If this article helps you in any way, great!

First off, I originally thought that Perl was some complex program that I’d have to run on my home computer. In fact, Perl needs only to be installed; there’s no need to “run” the Perl program to use scripts. Basically, Perl is there so that you can use it’s instructions to make use of pre-existing files that will allow you to do tasks like pushing glyphs or plans, building or placing halls, removing waste, etc. We’ll talk about those files later on.

A script is nothing more than a batch file, similar to batch files from DOS, ending in the extension .bat, and run in the DOS environment via the Command prompt (we’ll get to that later). You don’t have to be logged into the game to use them, you just need an internet connection. With a script, you can automate tasks and run them on a regular basis. Of course, using scripts also uses up rpc’s or remote procedure calls. In simple terms, the amount of scripted tasks you can perform or call up on the Lacuna site per day. You get 10000 rpc’s per day. You can see how much you have by clicking your profile in the game. Once you run out of rpc’s, you can’t do anymore scripting until the next day. But it’s not easy to use up that many rpc’s in a day, so for now don’t worry about using too many.

SECTION 2: Does everyone know how to open a command prompt? I learned back when DOS was the only operating system. For windows though, you either have to find the command prompt (usually buried in System tools, Windows tools or the like) or open it by pressing Windows Key-R, and typing “cmd” in the box. If you have Windows 7, click on Start and type “cmd” in the box at the bottom of the window.

SECTION ONE: I went to UF’s website and found his ACTIVEPERL Install (for windows) page. The first step was to download Perl . That was straightforward enough. I ended up with a file that had an .msi extension. I followed the directions to install. As I’m already setup as an Administrator when I start Windows, after right-clicking, I just selected INSTALL. I ran into problems at step 7, “Ensure that all the checkboxes are checked.“ I couldn’t check them on my system, but apparently that didn’t matter too much. I got through the remainder of the install without incident.

As I recall, all those ppm commands didn’t work at first when I typed them in on my system. While I could have used the SET PATH command to include the Perl folder as a place where Windows would look for files, I simply change folders, e.g.: at the command prompt type:”cd c:\perl” without the quotation marks. This proved to a problem later on as well, which we’ll get to soon.

SECTION 4: Extracting the zip file created lots of confusion for UF and me. I used a file manager other than Windows Explorer to extract the zip file, and forgot to check the box that says, “include original path (if any).” I ended up with all the files extracted to one folder instead of many. That took a while to figure out! When you extract this zip file to your computer, you should have a folder with several subfolders. Otherwise there’s a problem. By the way, the terms folder and subfolder are synonymous with directory and subdirectory. I prefer the later as that’s what I originally learned. Modifying the lacuna.yml configuration file was simple enough, I used Notepad. If for some reason you find it difficult to get Notepad to open the file, rename it: lacuna.txt. Then rename it back once you’re done editing. You’ll be using the lacuna.yml file in your scripts so you can log into your account.

SECTION 6: UF showed me a neat trick: instead of typing the commands listed:

I copied the displayed text by selecting with the mouse cursor and using Ctrl-C. Right-clicked in the upper left-hand corner of the command prompt window. Selected Edit, then Paste. This copied the commands to the prompt in a flash. You can also right-click, select Edit, then Mark, to copy text from the command prompt. This helped when I was sending copies of error messages back to UF via the chat window.

You’ll notice in the LE\GLC\examples folder, there are lots of files with the extension .pl. These are the files that Perl will be working with to perform different tasks.

SECTION 7: Here’s where I had some difficulty. On my system, when I open a command prompt, I always start out in the folder C:\Windows\System32. Instead of having to always navigate to the LE\GLC\examples folder, I wrote a batch file that I named Lacuna.bat and placed it in the Windows\system32 folder. Just one line:

cd c:\le\glc\examples

So typing “Lacuna” takes me to where I want to be without too much typing. Like I said, scripts are batch files. I tried running a script (batch file) but got an error message about not finding a file called DateTime.pm. It turned out this file really was present in the Perl\lib folder but Windows was not seeing it. At first we tried to set up a path so Windows could find it. SET PATH is an old DOS command and as I mentioned earlier, tells Windows where to look for files. UF suggested I could either write a separate batch file that I’d run and would set the path for me, or I could include a path statement at the beginning of my batch files. So for example: PATH=C:\PERL;C:\LE would tell Windows to look for files in those folders. But for some reason that didn’t work. I remembered an old trick and copied the file to the LE\GLC\examples folder, and then it worked.

So now I could experiment with scripts. I discovered that I no longer had to open the command prompt to run scripts. Much simpler to open Windows Explorer, find the batch file I wanted to run and double-click on it. Easy! I no longer needed the Lacuna.bat file I created earlier. But I wanted a recurring script, one that would do things every hour or whenever I wanted. So UF introduced me to a Perl command called sleep. Similar to the DOS command Pause, it pauses the script, keeping it open until the time you set for it to sleep is over and it can continue.

So for example: perl -e "sleep 3600" would pause the script for 1 hour. (60 seconds x 60 minutes=3600) But again, there was a problem. I was getting an error message saying it couldn’t find the perl.exe file. As I already knew, path was not working properly on my system. I tried resetting my computer, but no go. So I fixed it by simply inserting the full path in the line: C\perl\bin\ perl -e “sleep 3600” and that took care of that. I found the Sample script commands page on UF’s site to be very helpful. I was able to use the examples to create several simple scripts that I use. I especially liked the one that placed halls on my home world, no more tiresome clicking wth the mouse!

This concludes my first experience with Perl and scripting. Needless to say, I’ve only just scratched the surface. There’s lots more to learn, but I was happy enough to have gotten at least this far. And if I can do it, so too can you. Good luck and happy scripting!

Community notes #

These days most people find Strawberry Perl (http://strawberryperl.com/) easier to use on Windows than ActivePerl.