Reading Script Values
Use owner chat to see what a script knows about your build.
Try it on a box
Follow Your First Scripted Object to create a box and add an LSL script. Stop that script, replace its source with the example below, transpile and confirm the save, then run it from the box's Contents row. Return to gameplay before touching the box.
Download the value-reporting script
integer touches = 0;
default
{
state_entry()
{
llOwnerSay("Touch this box to read its values.");
}
touch_start(integer count)
{
++touches;
vector position = llGetPos();
float height = position.z;
llOwnerSay("Touches: " + (string)touches);
llOwnerSay("Height: " + (string)height);
llOwnerSay("Position: " + (string)position);
}
}
Each touch prints three messages to the object's owner. The integer
touches counts presses during this execution. A vector holds
three coordinates; position.z reads its height in LSL's
Z-up coordinate frame. Move the box with the build tools, return to
gameplay, and touch it again to read its new position.
If the box is at LSL position <1, 2, 3>, its first touch
reports:
Touches: 1
Height: 3.000000
Position: <1.00000, 2.00000, 3.00000>
Your coordinates will depend on where you put the box. See Coordinate Frames when comparing LSL coordinates with engine or native TypeScript values.
Turn a value into text
(string) converts an LSL value to text so it can join a
message. The declared type determines the display format.
| LSL expression | Text produced |
|---|---|
(string)2 | 2 |
(string)2.0 | 2.000000 |
(string)1.25 | 1.250000 |
(string)<1, 2, 3> | <1.00000, 2.00000, 3.00000> |
(string)ZERO_ROTATION | <0.00000, 0.00000, 0.00000, 1.00000> |
Finite floats display six decimal places. Vector and rotation components
display five. The Mono formatting profile also rounds to seven significant
decimal digits, so the printed text is not a lossless copy of every float.
For example, (string)12345665.0 produces
12345660.000000. Use the numeric value for calculations;
convert it to text when you want a readable message.
Native TypeScript display
Native TypeScript uses JavaScript number formatting. For example,
String(1.25) produces 1.25. A native vector's
toString() also keeps its native display format. The LSL
transpiler applies the LSL rules at explicit scalar string casts.
These examples describe individual values. List conversion and list element formatting have separate compatibility work; do not assume that casting a whole list uses this same scalar formatting path.
Check a revised script
After editing, confirm the save and run the newly compiled script. A retained executable keeps the code produced when it was compiled; Reset reloads that executable and is not a way to compile an unsaved edit or obtain a compiler update.
To finish this lesson, stop the script from its Contents row. Keep the box for your next experiment, or return to the colour-changing example.