The Beginning
page 3
Programming for the Genius-Impaired
A series of lessons for those who want to learn how to create their own Lightwave Plugins with Lscript.

Let's Talk Brackets

I know you're all itchy to jump right in and start programming, but there's a couple of thing about LScript we need to talk about. In Lscript (and a few other languages), brackets and semicolons play an important role in keeping thing organized.

Brackets {} are used in many situations to keep stuff sectioned off so the computer knows what's what. Mostly, certain commands* use brackets to keep track of what they are doing.  Think of them as fences that keep all the commands separated.  Don't sweat it too much, it'll start making sense soon. 

Consider the lowly semicolon. Ok, not too much.

In Lscript, the semicolon acts kind of like a period at the end of a sentence.  90% of the errors you'll come across are from forgetting to add a semicolon (the other 90% will be your fault...};^)

Another common bit of punctuation is //. When these two forward slashes appear on a line, it tells the computer that what follows is a programmer's comment, and should be ignored (This is frequently true in social settings, too...};^)

Comments are inserted by the programmer to help him/her remember what was going on in the program at certain points, to make the code more readable and easier to come back to at some time in the future, say for instance, the year 2000.**

To illustrate some of what was said above, here is the world's simplest LScript:
Before we start, I want to remind you that all the scripts in this tutorial are Modeler LScripts, and should only be run from Modeler. At then end of the tutorial, I'll show you how to change the script to run in Layout.

 

// Here's a really simple program,
// Says me, the programmer

main
{

info("Hello World!");

}

If you want to see what this does, just copy the text, paste it into a text file, and save it as test1.ls. Then, in Modeler, go to the Construction>Utility menu and choose Lscript. It will display a file requester. Navigate to where you saved the script, hi-light it and hit Open. So what is it really doing? It starts off with two lines of comments (those double slashes), which the computer ignores.

Then, it has a line that says main. Main has two brackets, which in this case contain the entire program.  Every Modeler LScript has to have a section called main.

Then the heart of our little program;  the command info,which pulls up a little info box. It'll look like the picture to the right. Notice that that words in quotes in our program are what showed up in the box.  Notice too, the info line ends with a ";"

Whenever we talk about LScript commands, I'll use a different font, so it will look like this. Sometimes, for emphasis, I'll make it bold and add color.
Ok, enough with the basics. Let's start on the meaty bits!


* Ok. LScript is a computer language, right? And languages are made of of words, and the way you are allowed to string words together is the grammar. So far so good. So like every good language, to really make sense of it, you need a dictionary. You can get a complete set of documentation from the Newtek Website. Down at the bottom of the page, you'll see the LScript User and Reference Manuals, and the LScript 2.6 Updates. These pretty much comprise the dictionary for LScript.

** This was a funny joke back when people thought the world was going to end in the year 2000 because of date-related bugs in the ancient code that runs banks, air-traffic control, etc. Most of this code was written in near-dead languages (KOBOL, PASCAL), and was, I'm sure, poorly commented.