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

Hey! We don't even have to learn much new stuff to do this next part, so let's talk about some of the different squiggly marks LScript uses to do simple math, the mathmatical operators*.

Mathmatical Operators
+ Add 3 + 5 = 8
- Subtract 3 - 5 = -2
* Multiply 3 * 5 = 15
/ Divide 3 / 5 = 0.6
^^ To the Power of 3 ^^ 5 = 243

But hey, you probably already knew that.

Enough with the math, Poindexter, let's add some code!

main 

   quitflag = 0;

    compnumber = random(1,10);   

    while(quitflag == 0)
    {

        reqbegin("Pick a Number"); 

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

            yourguess = 0; 

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

        if(reqpost()) 
        { 

            yourguess = getvalue(a1); 

        } 

        else 

            return; 

        reqend(); 

 

        if(yourguess == compnumber)
        {

            info("Congratulations! You Won!");

           quitflag = 1;

        }
        else
        {

            if(yourguess > compnumber)
            {
                info("Your guess is too big! Try again.");
            } 
            else
            {
                info("Your guess is too small! Try again.");
            }

        }
    }

}

 

The new code is pretty simple. Remember, this is the else part of the if/else that checked to see if your number matches the computer's number. Since this is in the else part, we only get to this code if your number is wrong. If your guess is wrong, that means there are only two possibilities remaining, either your number is to big, or it is too small.

We'll check for "too big" first. 

If yourguess is greater than the number the computer picked, compnumber, you get a message that says your guess is too big. 

Since there are only two possibilities, if yourguess isn't greater than the computer's number, the only choice left is "too small," so the else in this if/else gives you a message that says your guess is too small.

Would you believe there are only a couple of thing left to do? It's true!


* When we write quitflag = 0, or test + 5, we are writing expressions. In these two expressions, = and + are the operators, because they act, or operate, on the other bits of the expression. The other bits (quitflag, 0, test, 5) are called the operands. The good news is, you can probably live a happy and fullfilled life without ever remembering this fact.

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