From: Holocluck Henly
I finally had the time to sit down for more questions. As some recall I am stubbornly trying to get answers in an effort to learn LSL. Wiki sites and publications have so far failed me, having seemingly been written by programmers for programmers instead of beginners...
Actually wiki sites are written to be the basis for understanding the language. An API (Application Programming Interface) listing like lslwiki.net can be thought of as a dictionary, with each function explained in as basic detail as possible. As an added bonus, most pages supply examples of how to use that function in a practical sense. Programming can be a difficult thing to wrap your head around at first, but really all it takes is someone who knows their stuff to point you at a few things here and there.
From: Holocluck Henly
1. What is the significance of saying "total_number"? does this mean the script output will be detectable by or broadcast to anyone within range?
ex: touch_start(integer total_number)
Dylan answered this one, but I think a little more clarification through example might be necessary here.
touch_start(integer x) {
... // Do stuff
}
...is just as valid as total_number. The word (unbroken by white space) specified is the constant that will be used by the function. It's constant in the sense that while in the function, its value cannot be changed. However subsequent calls to the function might result in different values. For instance if two people touched something at the same moment, however unlikely, total_number might be 2 at one point. Usually it's 1 because the odds of more than one person starting to touch an object at the same time is very low.
From: Holocluck Henly
3. Is the following script a "trick question" script? It outputs the phrase 2x. The script suggests to output one more time than the designated number. The "while" line pretty much negates the "maxcount" line as a consideration here, right? Leaving the "count" line as "it" which makes it 1+1 for an output of 2x? Am I seeing this correctly?
...
This is a pretty common point of confusion for newbies. Like Dylan explained it does end after 2 iterations, as you had guessed (I think, it's very early in the morning for me and my ability to decipher your question is impared). What most people do in programming is rely on the fact that things tend to start at 0, such as list elements (or arrays, which we don't have access to in LSL, but will soon in other languages supplied through Mono), and llDetected*() calls. This usually results in people doing a comparison such as variable < desired_total. For the average person, number systems start at 1 (you tend to think of having 1 apple, rather than 0 apples, when you start counting), so a less confusing comparison would be variable <= desired_total.
count = 0;
maxCount = 2;
while (count < maxCount) {
count++; // Add 1 to count.
llOwnerSay("Count is " + (string)count);
}
This produces the output:
Count is 1
Count is 2
From: Holocluck Henly
"--" the term "decrement" sounds like something else. What does it mean and its purpose? wiki didnt help with this and neither did google actually.
++ and -- are programming terms for increment and decrement respectively. They're both programmer shortcuts to cut down on typing, as well as a more efficient way of adding or subtracting 1 to and from variables in most engines/compilers. It goes back to assembly, where there are two methods of adding 1 to a number. The first works like this:
ADD Variable, 1, Variable;
...this is, in order of appearance, our destination Variable, add 1 and Variable together. In the end Variable will be 1 larger than before. This is in comparison to:
INC Variable, 1;
Just by looking at these two, it's obvious that it's easier to type and understand the second example, but the INC operation (increment) is also able to complete faster. ADD has to access a memory location twice, INC has to access it only once. There's a subsequent DEC (decrement) in some implementations of assembly, but INC can also accept a negative number, doing the same job.
From: Holocluck Henly
(Wiki has a series of charts of operators here
http://wiki.secondlife.com/wiki/LSL_Operators which are riddled with programmer-ese, most of whose descriptions dont make sense for BEGINNERS [which as many of you know is my main gripe about all beginner guides I've come across for LSL]).
Actually this is almost entirely math. Type casting, shift left and shift right, and many of the assignment operations are programming, the rest is not. Shift left and shift right is related to binary. To use the example there:
eight = 4 << 1;
...it's better understood by looking at its binary number:
0000 0100 = 4
...and then shifting left:
0000 1000 = 8
Essentially each shift is multiplying or dividing (left or right) a number by 2 each place you shift. Shifting too far will remove bits from the number though, leading to inaccuracies, and is also a fault many newbies encounter when they first start into bit shifting.
The assignment operations, like += and -=, are shortcuts.
Variable += 1;
...is the same as:
Variable = Variable + 1;
As you can see, the first option is faster to type. Most programmers will consider the use of these as a sign of one's experience, the former style being more often used by experienced programmers and the latter style being used by newbies. That said, += isn't as immediately obvious, so everyone will use Variable = Variable + under certain circumstances. Since they both do the same thing, which ever you use doesn't matter.
From: Holocluck Henly
6. Actually looking at that abovementioned wiki page: what do "comparison equal" and "comparison not equal" mean versus these terms equal and not equal? I suppose an example for a scenario for one of them might explain their purposes
Comparison equal (==) and comparison not equal (!=) are used to separate one's self from assignment (=) and not (!) which will change values. Some languages don't differentiate between the uses of =, like some forms of BASIC, so you'll get the following:
IF Variable = 1 THEN
Variable = 2;
END IF
Compare to the C equivalent:
if (Variable == 1) {
Variable = 2; // This only occurs when Variable is 1
}
It might not be immediately obvious, but when debugging, one may wonder why values are changing where they shouldn't, and looking for = instances where they shouldn't is a lot easier in the second example. For instance:
if (Variable = 1) {
Variable = 2; // This ALWAYS occurs, because Variable is not being set to 0, which is false in programming
}
That's why comparison operators are needed.