The Beginning
page 6
Programming for the Genius-Impaired
A series of lessons for those who want to learn how to create their own Lightwave Plugins with Lscript.
Deeper Magic from Before the Dawn of Time

So now you have the first part of your requester, let's work on the next part, actually requesting something!  The new lines are added in green.

main 
{      compnumber = random(1,10); 

    reqbegin("Pick a Number"); 

       ctltext("","Pick a number between 1 and 10"); 

       yourguess = 0;

       a1 = ctlinteger("Your Guess",yourguess);

    if(reqpost()) 
    { 

       //  I told you we'd put stuff here later

       yourguess = getvalue(a1);

    } 
    else 
        return; 
    reqend(); 
}

This new code gives us the screen on the left. You can save it out as an .ls file and give it a try. Let's take a look at each of the new lines and see what all the fuss is about.

The big mojo in this new code is the line :

a1 = ctlinteger("Your Guess",yourguess);

The ctlinteger command is short for Control Integer, and it adds a control to the requester that takes an integer (or whole number) as input. That means it pops up a space where the user can type in a number.

Any command in LScript that starts with ctl is a control that can be added to a requester panel.

The usage (or grammar) for ctlinteger is: 

TemporaryStorage = ctlinteger("A Title",Variable);

The first part (in quotes) is a title that will show up to the left of the input field. In the image above, the title is "Your Guess" and it shows up to the left of the box with the zero.  The second part is a variable.  This is the variable where we will eventually store the number the user types in.

So what's that a1 = bit at the beginning of the line?  Until the user hits OK, none of this stuff is final, so the a1 is just a temporary bucket we throw the user's input into, and we will have to transfer it to a permanent bucket (Variable) soon. This a made up name, just like all the other variable names. Since programs can have lots of these little temporary buckets in a requestor, they usually just get a short name.

You'll notice right above the ctlinteger line is a line that says yourguess = 0;. Before we can add a control, we have to tell the program what the default value is going to be. The first time we use a variable in a script, we usually assign it a default value. This is called initializing a variable. We're pre-filling the bucket with a neutral value.

Remember, the computer is very literal minded, and needs to be told everything. By adding this line, we tell the computer to start the requester with a 0 in the input field.

Finally, if the user clicks OK, we need to move their input out of temporary storage (a1) and move it where it belongs, in the variable yourguess.

yourguess = getvalue(a1);

The command for moving the user's input out the requester's temporary storage and into a real variable is getvalue.

All right...get up, stretch those legs a bit, grab a beverage and a snack, then get back here and we'll add some more widgets!

<<PREV 1 2 3 4 5 6 7 8 9 A B NEXT>>