I noticed there were a few hits on my blog with "lsl follow avatar" search terms on google. Assuming that the people are looking for a "pet" script, I thought it would be a good idea to put a reference to it - especially since it is actually on lslwiki here, search for "follow (script)" inside the page, the script is just below.
While looking for it, I found that I can kill the "lsl basic" topic - it is all too well described by a series of the articles in Dr.Dobbs journal article on using the linden scripting language. Quite a nice tutorial.
Sunday, July 22, 2007
You asked for it: lsl follow avatar script
Posted by
Dalien
at
8:04 AM
1 comments
Friday, June 8, 2007
Adding the mood...
I deliberately did not talk too much about states and asked a question about state_entry :)
Today we go with a slightly more interesting example to try.
Create a new object, and put the following script into it.
default
{
state_entry()
{
llOwnerSay("I am serious");
}
on_rez(integer i)
{
llOwnerSay("rezzed serious");
}
touch_start(integer total_number)
{
llOwnerSay("changing state from serious to happy...");
state happy;
}
}
state happy
{
state_entry()
{
llOwnerSay("I am happy!");
}
on_rez(integer i)
{
llOwnerSay("rezzed happy");
}
touch_start(integer total_number)
{
llOwnerSay("changing state from happy to serious...");
state default;
}
}
this script has two states, which represent the moods - one - default - is serious, and the other is "happy". (hmm can I be happy while still being serious ? I guess so, but anyway let's assume it is not the case for training purposes :)
This script switches to another state when the object is being touched.
By playing with it, we can find few interesting things:
- the "state_entry()" gets called every time the object enters the state
- after script editing the first state is always "default"
- taking the running script into the inventory does not change its state
Why would the states be useful ? They could be helpful to alter the behaviour of the script you have - like in this case, the touch of the object causes different reactions.
Also, you can see the logic in the script quite easily. However, changing the state does reset some things, for example, listeners which are installed using llListen, so this is something to keep in mind.
Homerwork:
- modify the script such that it contains the third state, "sad", and the clicks
on the object cause transition serious->sad->happy-serious (etc). - take a look at the state_exit event, and try to put some wording into it - and see when it does get executed.
This should provide enough material to experiment with, till the next post.
Posted by
Dalien
at
3:57 AM
2
comments
Labels: lsl basic
Thursday, June 7, 2007
What's in those bags with garbage ?
Ok, apparently the first post caused very unexpected (by me that is :) positive reaction, so let's continue.
Again, I set the pace rather slow, so that noone would stress too much.
Let's return to our small example and study those "trash bags" with curly brackets.
default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}
touch_start(integer total_number)
{
llSay(0, "Touched.");
}
}
So, first - the outermost layer. The green thing. In LSL it is called state.
Those impatient can read up about it on wiki, for the rest - just consider this construct a part of reality for now. we'll deal with it later on sometime.
Now, the blue and red things.. those are more interesting. They describe how your script should react on certain events. There're a couple of dozen of events or so which can happen - and in the above code, inside those blocks you define what to do for each of the events.
Question: why is there a brown-coloured thing for the red-coloured event ? It is a way to say "when this happens, there will be some other information arriving". For this particular case, it will be the integer, which says how many agents are just starting to touch the object.
Some homework for those interested:
- find out what is "state_entry()" used for
- what does "0" in llSay mean and do you think it is the best way to have have it used in this way ?
- for the daring ones: find out how to do such that only you (the owner) could hear what the script is saying.
Posted by
Dalien
at
3:21 AM
3
comments
Labels: lsl basic
Wednesday, June 6, 2007
Basic LSL
There's been ton of the various tutorials and such about LSL, so not sure if this would be of use for anyone... but since a couple of folks said that this might be fun, here it goes. I will take an assumption that the reader is not very well versed in coding, so it is also an opportunity for me to exercise my explanation skills - and to start really really basic. So if this is boring for you - I will try to put some more spicy stuff inbetween :)
Let's take a practical approach - pushing random buttons and seeing what happens :)
Create a cube, and hit the "New Script" within the "Content" tab.
As a result we get "New Script" which looks like this:
default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}
touch_start(integer total_number)
{
llSay(0, "Touched.");
}
}
Now, what what here, and why so many curly braces ?
if you look closer, you will see that all of this seems to be similar - a series of nested structures.
And at highlevel it looks like this:
some-name(maybe brackets and some more brackets)
{
some-inside-stuff
}
This kind of logic is very frequently used in computer science - and not only.
When you have tons of garbage that you do not want to see spreading around the house, you take a bag, put all the garbage in - and put the label "garbage". And you know that it contains various garbage.
Same in the computer science - the concept of packing multiple things and then referring to them by a single name allows to abstract away "the garbage" so that you can operate at a higher level of abstraction.
Posted by
Dalien
at
3:34 AM
5
comments
Labels: lsl basic