Difference between revisions of "Hello Avatar"

From Second Life Wiki
Jump to navigation Jump to search
m (add tag LSLC|Tutorials)
m (catch up the intriguing source lines suggested here with the list at Chatbot)
Line 50: Line 50:
<pre>
<pre>
         llSetColor(<0.3, 0.3, 0.3>, ALL_SIDES); // darken
         llSetColor(<0.3, 0.3, 0.3>, ALL_SIDES); // darken
         llSetColor(<1, 1, 1>, 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
</pre>
</pre>
Line 64: Line 64:
<pre>
<pre>
         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
         llSetPos(llGetPos() - <0.0, 0.0, 2.1>); // teleport back down the Z axis
         llSetPos("+"(llGetPos(), <0.0, 0.0, -2.1>)); // teleport back down the Z axis
         llSetLocalRot(llEuler2Rot(<0.0, 0.0, PI_BY_TWO>)); // face one way
         llSetLocalRot(llRotBetween(<1, 0, 0>, llGetSunDirection())); // turn the East face to the Sun
         llSetLocalRot(llEuler2Rot(ZERO_VECTOR)); // face another way
         llSetLocalRot(llEuler2Rot(ZERO_ROTATION)); // turn the East face to the East
         llSetStatus(STATUS_PHYSICS, TRUE); llSleep(0.1);
         llSetStatus(STATUS_PHYSICS, TRUE); llSleep(0.1);
         llSetBuoyancy(0.9); // bounce well, without floating
         llSetBuoyancy(0.9); // bounce well, without floating
Line 77: Line 77:
* Poke around inside the object running the script:
* Poke around inside the object running the script:
<pre>
<pre>
         llOwnerSay(llList2CSV([ZERO_VECTOR, FALSE, TRUE, STATUS_PHYSICS, PI])); // reveal some named code values
         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(llList2CSV( [ZERO_VECTOR, FALSE, TRUE, STATUS_PHYSICS, PI] )); // some named code values
</pre>
</pre>


Line 84: Line 85:
<pre>
<pre>
         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
</pre>
</pre>


{{#vardefine:sort|Hello Avatar}}{{LSLC|Library}}{{LSLC|Examples}}
{{#vardefine:sort|Hello Avatar}}{{LSLC|Library}}{{LSLC|Examples}}
{{LSLC|Tutorials}}
{{LSLC|Tutorials}}

Revision as of 18:04, 15 September 2007

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:

default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
    }

    touch_start(integer total_number)
    {
        llSay(0, "Touched.");
    }
}

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

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:

default
{
    state_entry()
    {
        llSetText("look at me blue", <0.0, 0.0, 1.0>, 1.0);
        llOwnerSay("OK");
    }
}

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:
        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
  • Twiddle the label of the object running the script:
        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
  • Move and rotate while not physical, then kick and spin while physical and bouncy.
        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_ROTATION)); // 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
  • Poke around inside the object running the script:
        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
  • Chat a question for you the object's owner to answer (and then chat the answer that you chose):
        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