Difference between revisions of "Hello Avatar"
(and also explain how llRemoveInventory(llGetScriptName()) helps newbies learn by dragging scripts to run them) |
m (change to LSL from PRE tags) |
||
Line 5: | Line 5: | ||
The script you get from the SL GUI, when first you ask to create a New Script in an object or in your inventory, was this script, as of 2007-08: | The script you get from the SL GUI, when first you ask to create a New Script in an object or in your inventory, was this script, as of 2007-08: | ||
< | <lsl> | ||
default | default | ||
{ | { | ||
Line 18: | Line 18: | ||
} | } | ||
} | } | ||
</ | </lsl> | ||
That script shows you how to get something to happen when you save or reset the script. | That script shows you how to get something to happen when you save or reset the script. | ||
Line 30: | Line 30: | ||
For example, you might try: | For example, you might try: | ||
< | <lsl> | ||
default | default | ||
{ | { | ||
Line 39: | Line 39: | ||
} | } | ||
} | } | ||
</ | </lsl> | ||
Each time you edit and Save, the SL GUI will compile and run your new line of code. Every time you click Reset, the SL GUI will run your one line of code again. | Each time you edit and Save, the SL GUI will compile and run your new line of code. Every time you click Reset, the SL GUI will run your one line of code again. | ||
Line 48: | Line 48: | ||
* Twiddle the red, green, and blue intensity, also the "alpha" opacity/ transparency: | * Twiddle the red, green, and blue intensity, also the "alpha" opacity/ transparency: | ||
< | <lsl> | ||
llSetColor(<0.3, 0.3, 0.3>, ALL_SIDES); // darken | llSetColor(<0.3, 0.3, 0.3>, ALL_SIDES); // darken | ||
llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES); // lighten | llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES); // lighten | ||
llSetAlpha(0.7, ALL_SIDES); // make translucent | llSetAlpha(0.7, ALL_SIDES); // make translucent | ||
</ | </lsl> | ||
* Twiddle the label of the object running the script: | * Twiddle the label of the object running the script: | ||
< | <lsl> | ||
llSetText("look at me green", <0.0, 1.0, 0.0>, 1.0); // label | llSetText("look at me green", <0.0, 1.0, 0.0>, 1.0); // label | ||
llSetText("look at me black", <0.0, 0.0, 0.0>, 1.0); // label differently | llSetText("look at me black", <0.0, 0.0, 0.0>, 1.0); // label differently | ||
llSetText("", <0.0, 0.0, 0.0>, 1.0); // do not label | llSetText("", <0.0, 0.0, 0.0>, 1.0); // do not label | ||
</ | </lsl> | ||
* Move and rotate while not physical, then kick and spin while physical and bouncy. | * Move and rotate while not physical, then kick and spin while physical and bouncy. | ||
< | <lsl> | ||
llSetStatus(STATUS_PHYSICS, FALSE); llSleep(0.1); | llSetStatus(STATUS_PHYSICS, FALSE); llSleep(0.1); | ||
llSetPos(llGetPos() + <0.0, 0.0, 2.1>); // teleport up the Z axis | llSetPos(llGetPos() + <0.0, 0.0, 2.1>); // teleport up the Z axis | ||
Line 73: | Line 73: | ||
llApplyRotationalImpulse(<0.0, 0.0, 3.0>, TRUE); // yaw about the Z axis | llApplyRotationalImpulse(<0.0, 0.0, 3.0>, TRUE); // yaw about the Z axis | ||
llSetStatus(STATUS_PHYSICS, FALSE); llSetStatus(STATUS_PHYSICS, TRUE); // zero rot inertia | llSetStatus(STATUS_PHYSICS, FALSE); llSetStatus(STATUS_PHYSICS, TRUE); // zero rot inertia | ||
</ | </lsl> | ||
* Poke around inside the object running the script: | * Poke around inside the object running the script: | ||
< | <lsl> | ||
llOwnerSay( (string) llGetAgentSize(llGetLinkKey(llGetNumberOfPrims())) ); // often not ZERO_VECTOR while avatar sits | llOwnerSay( (string) llGetAgentSize(llGetLinkKey(llGetNumberOfPrims())) ); // often not ZERO_VECTOR while avatar sits | ||
llOwnerSay( (string) llKey2Name(llGetLinkKey(llGetNumberOfPrims())) ); // often the name of the sitting avatar | llOwnerSay( (string) llKey2Name(llGetLinkKey(llGetNumberOfPrims())) ); // often the name of the sitting avatar | ||
llOwnerSay(llList2CSV( [ZERO_VECTOR, FALSE, TRUE, STATUS_PHYSICS, PI] )); // some named code values | llOwnerSay(llList2CSV( [ZERO_VECTOR, FALSE, TRUE, STATUS_PHYSICS, PI] )); // some named code values | ||
</ | </lsl> | ||
* Chat a question for you the object's owner to answer: | * Chat a question for you the object's owner to answer: | ||
< | <lsl> | ||
llDialog(llGetOwner(), "A clarifying demo?", ["No", "Yes"], 7); // chat some Q & A | llDialog(llGetOwner(), "A clarifying demo?", ["No", "Yes"], 7); // chat some Q & A | ||
llDialog(llGetOwner(), "Choose an arc:", ["PI_BY_TWO", "PI", "TWO_PI"], 7); // chat some Q & A | llDialog(llGetOwner(), "Choose an arc:", ["PI_BY_TWO", "PI", "TWO_PI"], 7); // chat some Q & A | ||
</ | </lsl> | ||
These [[llDialog]] examples start you into a new lesson that could be your next lesson: the work of learning how scripts and avatars communicate with one another. In particular, you could also learn to make sense of such examples as: | These [[llDialog]] examples start you into a new lesson that could be your next lesson: the work of learning how scripts and avatars communicate with one another. In particular, you could also learn to make sense of such examples as: | ||
< | <lsl> | ||
llRequestAgentData(llGetOwner(), DATA_BORN); // the data-of-birth of the owning avatar | llRequestAgentData(llGetOwner(), DATA_BORN); // the data-of-birth of the owning avatar | ||
</ | </lsl> | ||
The parameter 7 shown in the llDialog examples chooses a chat channel on to which the llDialog call will copy the answer you give to the question, as if you had chatted it yourself. You can see this happen if you learn to code a receiver for [[listen]] events. Similarly, if you learn to code a receiver for [[dataserver]] events, then you can [[llOwnerSay]] the results of the [[llRequestAgentData]] example. | The parameter 7 shown in the llDialog examples chooses a chat channel on to which the llDialog call will copy the answer you give to the question, as if you had chatted it yourself. You can see this happen if you learn to code a receiver for [[listen]] events. Similarly, if you learn to code a receiver for [[dataserver]] events, then you can [[llOwnerSay]] the results of the [[llRequestAgentData]] example. | ||
Line 98: | Line 98: | ||
Likely you want to make time to learn how to have one script call another before you run out of space in the one script you know how to write. To ask how much memory exists (in the task of the script of the object) that you never have yet filled with allocations of byte code, stack, or heap, try running code like: | Likely you want to make time to learn how to have one script call another before you run out of space in the one script you know how to write. To ask how much memory exists (in the task of the script of the object) that you never have yet filled with allocations of byte code, stack, or heap, try running code like: | ||
< | <lsl> | ||
llOwnerSay( (string) llGetFreeMemory() ); | llOwnerSay( (string) llGetFreeMemory() ); | ||
</ | </lsl> | ||
== Drag To Run Memorable Snippets of Code == | == Drag To Run Memorable Snippets of Code == | ||
Line 106: | Line 106: | ||
Instead of always editing scripts inside an object that you might lose, you may prefer to choose New Script and edit and Save in the Inventory > Scripts folder and drag the script on to an object to run a new copy when you please. If you're dragging to run the script, you'll see the object ends up holding confusingly many copies. So you'll quickly want to learn how to tell a script to delete itself after being dragged in place to run, thus: | Instead of always editing scripts inside an object that you might lose, you may prefer to choose New Script and edit and Save in the Inventory > Scripts folder and drag the script on to an object to run a new copy when you please. If you're dragging to run the script, you'll see the object ends up holding confusingly many copies. So you'll quickly want to learn how to tell a script to delete itself after being dragged in place to run, thus: | ||
< | <lsl> | ||
llRemoveInventory(llGetScriptName()); | llRemoveInventory(llGetScriptName()); | ||
</ | </lsl> | ||
Enjoy! | Enjoy! |
Revision as of 14:50, 1 January 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
The New Script
The script you get from the SL GUI, when first you ask to create a New Script in an object or in your inventory, was this script, as of 2007-08:
<lsl> default {
state_entry() { llSay(0, "Hello, Avatar!"); }
touch_start(integer total_number) { llSay(0, "Touched."); }
} </lsl>
That script shows you how to get something to happen when you save or reset the script.
The example thing that happens is { llSay(0, "Hello, Avatar!"); }. The other example thing happens when you touch the object.
How To Try New Lines of Code
To create your first copy of this script, you're supposed to find the New Script button in the Content tab (beside the General, Object, Features, and Texture tabs). Then you're supposed to notice that you can edit this script and click the Save button repeatedly to try out new code.
For example, you might try:
<lsl> default {
state_entry() { llSetText("look at me blue", <0.0, 0.0, 1.0>, 1.0); llOwnerSay("OK"); }
} </lsl>
Each time you edit and Save, the SL GUI will compile and run your new line of code. Every time you click Reset, the SL GUI will run your one line of code again.
Your First New Lines of Code
Exploring new commands in this way can run you thru a long series of demoes that teach you about how scripts work, such as the following.
- Twiddle the red, green, and blue intensity, also the "alpha" opacity/ transparency:
<lsl>
llSetColor(<0.3, 0.3, 0.3>, ALL_SIDES); // darken llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES); // lighten llSetAlpha(0.7, ALL_SIDES); // make translucent
</lsl>
- Twiddle the label of the object running the script:
<lsl>
llSetText("look at me green", <0.0, 1.0, 0.0>, 1.0); // label llSetText("look at me black", <0.0, 0.0, 0.0>, 1.0); // label differently llSetText("", <0.0, 0.0, 0.0>, 1.0); // do not label
</lsl>
- Move and rotate while not physical, then kick and spin while physical and bouncy.
<lsl>
llSetStatus(STATUS_PHYSICS, FALSE); llSleep(0.1); llSetPos(llGetPos() + <0.0, 0.0, 2.1>); // teleport up the Z axis llSetPos(llGetPos() + <0.0, 0.0, -2.1>); // teleport back down the Z axis llSetLocalRot(llRotBetween(<1, 0, 0>, llGetSunDirection())); // turn the East face to the Sun llSetLocalRot(llEuler2Rot(ZERO_VECTOR)); // turn the East face to the East llSetStatus(STATUS_PHYSICS, TRUE); llSleep(0.1); llSetBuoyancy(0.9); // bounce well, without floating llApplyImpulse(<0.0, 0.0, 1.0>, TRUE); // advance along the Z axis llApplyRotationalImpulse(<0.0, 0.0, 3.0>, TRUE); // yaw about the Z axis llSetStatus(STATUS_PHYSICS, FALSE); llSetStatus(STATUS_PHYSICS, TRUE); // zero rot inertia
</lsl>
- Poke around inside the object running the script:
<lsl>
llOwnerSay( (string) llGetAgentSize(llGetLinkKey(llGetNumberOfPrims())) ); // often not ZERO_VECTOR while avatar sits llOwnerSay( (string) llKey2Name(llGetLinkKey(llGetNumberOfPrims())) ); // often the name of the sitting avatar llOwnerSay(llList2CSV( [ZERO_VECTOR, FALSE, TRUE, STATUS_PHYSICS, PI] )); // some named code values
</lsl>
- Chat a question for you the object's owner to answer:
<lsl>
llDialog(llGetOwner(), "A clarifying demo?", ["No", "Yes"], 7); // chat some Q & A llDialog(llGetOwner(), "Choose an arc:", ["PI_BY_TWO", "PI", "TWO_PI"], 7); // chat some Q & A
</lsl>
These llDialog examples start you into a new lesson that could be your next lesson: the work of learning how scripts and avatars communicate with one another. In particular, you could also learn to make sense of such examples as:
<lsl>
llRequestAgentData(llGetOwner(), DATA_BORN); // the data-of-birth of the owning avatar
</lsl>
The parameter 7 shown in the llDialog examples chooses a chat channel on to which the llDialog call will copy the answer you give to the question, as if you had chatted it yourself. You can see this happen if you learn to code a receiver for listen events. Similarly, if you learn to code a receiver for dataserver events, then you can llOwnerSay the results of the llRequestAgentData example.
Likely you want to make time to learn how to have one script call another before you run out of space in the one script you know how to write. To ask how much memory exists (in the task of the script of the object) that you never have yet filled with allocations of byte code, stack, or heap, try running code like:
<lsl>
llOwnerSay( (string) llGetFreeMemory() );
</lsl>
Drag To Run Memorable Snippets of Code
Instead of always editing scripts inside an object that you might lose, you may prefer to choose New Script and edit and Save in the Inventory > Scripts folder and drag the script on to an object to run a new copy when you please. If you're dragging to run the script, you'll see the object ends up holding confusingly many copies. So you'll quickly want to learn how to tell a script to delete itself after being dragged in place to run, thus:
<lsl> llRemoveInventory(llGetScriptName()); </lsl>
Enjoy!