Practical Applications of the Update

It’s an ill wind that doesn’t blow some good…and one of the new API functions added in 1.13 has inspired a quick hack from me that is both ingenious and helpful.

We have a private build-pad floating high above the Evans Family Compound now (high enough to conform with Fantasyland regulations, of course), and I’ve been letting Allie borrow it to work on some of her creations. It occurred to me that she might want to keep track of how many prims her creations were using…and, to that end, I invented a “prim scale.”

// Prim Scale Script
// Erbo Evans - 12/3/2006

integer s_tare = 0;
vector s_pos;

    integer count = llGetParcelPrimCount(s_pos,PARCEL_COUNT_TOTAL,FALSE);
    integer real = count - s_tare;
    llSetText("Prim count: " + (string)real + "\nClick to set tare.",<1,1,1>,1.0);

        s_pos = llGetPos();

    touch_start(integer total_number)
        s_tare = llGetParcelPrimCount(s_pos,PARCEL_COUNT_TOTAL,FALSE);


This displays a running count of the total prims being used on the parcel, and, if you click it, sets the current prim count as a “tare” amount, so that one may click on the “scale” object, then start building, and have an accurate running count of the number of prims created since the “tare” was set. The display is updated every 10 seconds.

The display work is pretty much all done in the display() routine, which is called by all three event handlers. The key is the use of the new llGetParcelPrimCount() API, which returns the number of prims (of various types, depending on the second argument) on the parcel at the location given by the first argument. We use the value of llGetPos() for that first argument, to specify “the parcel where I am right now.” The third argument is the “sim-wide” flag, which obviously we want as FALSE. The “tare” value, which is used to bias the output, is stored as s_tare, initialized to 0 and set in the touch_start() handler.

Obviously, this is very simple, and there are a few improvements I could think of yet…but even this device makes a nice little tool for keeping track of how many prims you’re using in a build.



Filed under Scripthackery

2 responses to “Practical Applications of the Update

  1. Becky Tardis

    Evans, WordPress apparently doesnt wordwrap, and so chopped the lines to fit. 😦

  2. Actually, that’s my fault; I enclosed the code in PRE tags to keep it from being reformatted. Unfortunately, this makes some of the lines of code extend under the sidebars on the right. If you highlight it and copy it to the clipboard, though, you’ll find the code is intact. It also looks intact in the RSS feed.

    I should probably wrap that code snippet up as a text file and include it as a link, though.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s