Chatbot

From Second Life Wiki
Revision as of 21:48, 7 September 2007 by Ppaatt Lynagh (talk | contribs) (correct undoc'ed test cases such as first parameter has list type by slicing via listGetBetween and stringGetBetween a la article Slice_List_String_Etc)
Jump to navigation Jump to search

This script lets you chat some new example LSL code on a channel, and then see this script compile and run that code for you.

This script works like the Prefix Calculator script, but lets you ask for more than arithmetic while working with data types other than fixed point numbers.

If you're new, you might prefer to edit one line of a short script, click Save to run once, click Reset to run again indefinitely many times, as explained by the Hello Avatar article.

The Demo

For example, you can chat the LSL commands to make the default wood box translucent and bouncy and then kick it around and spin it, as follows ...

Twiddle the red, green, and blue intensity, also the "alpha" opacity/ transparency:

/7 llSetColor(<0.3, 0.3, 0.3>, ALL_SIDES); // darken
/7 llSetColor(<1, 1, 1>, ALL_SIDES); // lighten
/7 llSetAlpha(0.7, ALL_SIDES); // make translucent

Twiddle the label of the object running the script:

/7 llSetText("look at me green", <0.0, 1.0, 0.0>, 1.0); // label
/7 llSetText("look at me black", <0.0, 0.0, 0.0>, 1.0); // label differently
/7 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.

/7 llSetStatus(STATUS_PHYSICS, FALSE);
/7 llSetPos("+"(llGetPos(), <0.0, 0.0, 2.1>)); // teleport up the Z axis
/7 llSetPos("-"(llGetPos(), <0.0, 0.0, 2.1>)); // teleport back down the Z axis
/7 llSetLocalRot(llEuler2Rot(<0.0, 0.0, PI_BY_TWO>))); // face one way
/7 llSetLocalRot(llEuler2Rot(ZERO_ROTATION)); // face another way
/7 llSetStatus(STATUS_PHYSICS, TRUE);
/7 llSetBuoyancy(0.9); // resist gravity, but don't float
/7 llApplyImpulse(<0.0, 0.0, 1.0>, TRUE); // advance along the Z axis
/7 llApplyRotationalImpulse(<0.0, 0.0, 3.0>, TRUE); // yaw about the Z axis
/7 llSetStatus(STATUS_PHYSICS, FALSE); llSetStatus(STATUS_PHYSICS, TRUE); // zero rot inertia

Poke around inside the object running the script:

/7 llGetAgentSize(llGetLinkKey(llGetNumberOfPrims())) // often not ZERO_VECTOR while avatar sits
/7 ZERO_VECTOR, FALSE, TRUE, STATUS_PHYSICS, PI // reveal some named code values

Chat a question for you the object's owner to answer (and then chat the answer that you chose):

/7 llDialog(llGetOwner(), "A clarifying demo?", ["No", "Yes"], 7); // chat some Q & A

Your Experience

The LSL commands quoted above often do work as described in their // comments. The commands work if chatted in the order shown. The commands work if chatted at the usual wood box built by default in the SL GUI (0.5 x 0.5 x 0.5 m).

To see how the weight and shape of an object influence its response to commands that require STATUS_PHYSICS TRUE, try sending these commands to other objects.

To see how force multiplies, try adding this script more than once to an object.

To keep this article short, this script understands only some of the language that may interest you. We hope you'll find it easy to teach this script to understand whichever part of the LSL language you next want to explore. Just by trying, you can see that this script doesn't understand the less commonly useful library function names, arithmetic operators, code constant names, control flow keywords, punctuation marks, etc. Nor does this script understand any of your own function names, until you add those functions to this script.

As you first try speaking more of the LSL language, please don't trust this script too much. If you find you get confused over what this script thinks an LSL command means, please consider slowing down enough to design a small one-off experimental script to show you what the SL GUI thinks the command means. When you find a difference between what the SL GUI thinks and what this script thinks, that's a bug. We welcome you blogging your experience into the discussion tab of this article, to help us track bugs, to help us dream up new tutorial demoes, to encourage our work here, etc.

Enjoy,

P.S. Ppaatt Lynagh launched this tutorial project in 2007-09. "Allow anyone to copy", "next owner can copy & modify", and "mark item for sale price L$10" (to make microcredit donation easy), were the rights on Pat's copies of this script in SL, as of 2007-09-06.

P.P.S. The code of the sample script follows:

The Script