Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

More beginner questions

Holocluck Henly
Holographic Clucktor
Join date: 11 Apr 2008
Posts: 552
06-06-2008 00:33
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...

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)

2. What would be the purpose of llfrand? Its use is mentioned as "returns a random (numeric?) value" but why would one want to? Can someone give an example?

I visited another script guide location inworld last night and gathered up questions which were either still unclear as with looking at them earlier in wiki etc, or needed better clarification from you experts to possibly understand more.

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?

touch_start(integer total_number)
{
integer count = 1;
integer maxcount = 3;
while (count < maxcount)
{
llSay(0,"I'm repeating myself";);
count = count + 1;
}
}


4. "do-while" was mentioned but not explained in the demo.

5. Here are some unclear terms and variables:

"!=" means "not equal to"? The bash is a negative character" Is this its consistent role in LSL?

"--" the term "decrement" sounds like something else. What does it mean and its purpose? wiki didnt help with this and neither did google actually.

(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]).

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

Thanks for anyone who doesnt throw me a wiki URL can confirm or explain any of this in layman's terms.
Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
06-06-2008 01:59
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)


total_number is just a name you give to a variable. It could be anything. The integer variable declared in the parameters for touch_start for example seems to refer to the number of touches the object receives simultaneously. Personally I've never used it for anything, but conceivably it could come in hand when you're scripting things like games or weapons.

From: someone
2. What would be the purpose of llfrand? Its use is mentioned as "returns a random (numeric?) value" but why would one want to? Can someone give an example?


Well, you need a random number for any kind of random effect you want to create. Example: I made a Plato bust once that chatted random quotes from a notecard at random intervals. So I needed a random number for the notecard lines and another one for the timer interval. Or say you're scripting a game that involves rolling dice. Or picks out random people from the audience. Etc.

From: someone
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?


touch_start(integer total_number)
{
integer count = 1; // the variable "count" starts with this value
integer maxcount = 3; //"maxcount" will remain unchanged
while (count < maxcount) //i.e. while count is either 1 or 2
{
llSay(0,"I'm repeating myself";); //output the phrase
count = count + 1; //increase "count"
}
}

So "count" is 1 when you first touch it; condition is met, phrase will be chatted and "count" increased to 2, so the condition is still met when you touch it again; phrase will be chatted again, but then "count" will be set to 3, so the condition is no longer met. The object won't do anything at all anymore until you reset it, thereby setting "count" back to 1.

From: someone
4. "do-while" was mentioned but not explained in the demo.


http://www.lslwiki.net/lslwiki/wakka.php?wakka=dowhile says it all.

5. Here are some unclear terms and variables:

From: someone
"!=" means "not equal to"? The bash is a negative character" Is this its consistent role in LSL?


Yes.

From: someone
"--" the term "decrement" sounds like something else. What does it mean and its purpose? wiki didnt help with this and neither did google actually.


"decrement" as opposed to "increment", meaning subtracting 1 from an integer.

From: someone
(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]).


Hehe you're right, I don't understand some of these operators either, but I never had need yet of those I don't understand, so I shouldn't worry about that too much.

From: someone
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


Umm, two things are being compared and the result is they are either equal or not equal. I guess I don't quite see your difficulty with this.
Feynt Mistral
Registered User
Join date: 24 Sep 2005
Posts: 551
06-06-2008 05:38
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.
_____________________
I dream of a better tomorrow in SL!
You should too. Visit, vote, voice opinions.
Support CSG! Tell LL how much it would mean to subtract one prim from another!
Prim Animation! Stop by and say something about it, show your support!
Holocluck Henly
Holographic Clucktor
Join date: 11 Apr 2008
Posts: 552
06-09-2008 08:58
Thanks but some of the answers chased me away.
I need help on a layman's level. I have never programmed and I do not think like a programmer. I cant see a script the same way - yet at any rate.

I won't be chased away from scripting again.

I spent two hours with a very generous SLer last night and we went over what you might call a simple script. Everything was explained and it helped. I might not be able to make everything myself just yet, but I certainly have some points of reference and can follow other simple scripts to adapt to my needs.

_Dylan_: Thank you re llFrand. Later that week I went to a gallery where some statue was outputting a phrase periodicially, sometimes the same one twice in a row. I'll assume that was llFrand in action.

_Feynt_: How can the touch_start mean anything if Dylan explained that total_number means any number of people can touch the object at the same time? Actually in a group situation that can be important. At a recent show and tell there were probs when 50+ people clickied an object. It had to be revised to limit to how many it would respond to at a time.

Thanks both for explaining the Count script from Bromley.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
06-09-2008 09:40
total_number doesn't indicate the number of people who _could_ touch, it is set to the number who _have_ touched at that particular point in time.

I usually use just "n" here, it being shorter, but take:

touch_start(integer n)
{
llSay(0, "Number of people touching this object: " + (string)n);
}

as an example. Whenever someone starts touching the object, if there is a touch_start event in your script, the code inside it will trigger, and n, or touch_start, or whatever name you've given to the parameter will be filled in with the number of people touching it at that particular time.

(Putting (string) in front of the n turns it into a string i.e. some text, rather than a simple number. One can only say strings, rather than numbers.)

The number I think is limited to 14, so yes, if lots of people touch it at once there will be a problem - it won't know about anyone over number 14. Normally though, n is rarely greater than 1.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names