LSL Script Count

By Xah Lee. Date:

Michael Jergens wrote to ask:

This might be worthy of a post onto your website/blog and/or as a reply via email:

Subj: Script counts

this seems to be getting more attentions in sims such as New Jessie. My AV is scanned and I get a posting as to my script count and resource usage. I can understand why they would want to do this; however, it is difficult to sometimes track down ALL of my scripts. For example: New Jessie says I am using 31 scripts and 1.4 mb. Scripts I understand, but the “1.4 mb” is a little more vague to me. Is that even within my control? Is it a result of the script counts (i.e. more scripts active means higher “mb”)

Some of the scripts I can track down by right click/'inspect' on various HUD attachments and objects. I tried a similar thing on my AV and found almost all were ZERO scripts. Logically, I can conclude that either my Viewer identifies scripts in a different way than the sim does or I am not digging deep enough to find stealthy scripts. I did learn one tidbit regarding 'stealth' scripts: clothing! Sometimes there are scripts to resize or to change color. I was told that once you get an article to appear the way you want it, you can then go in and delete the scripts. However, this usually only amounts to 1 or 2 scripts, but it is a start. My goal is to go into SL combat and to have essential combat gear: a primary weapon, a secondary weapon, a munitions HUD and maybe a melee item (if the primary weapon does not have one). Having better educated SL users can help to trim scripts down without reducing the fun part. I will start by educating myself.

I would welcome any information you may offer!

Hope you are well and wishing you continued success in your web/blog venture (8000 hits daily??? impressive!)

Kind regards,

Mike Jergens
"Humourous Maximus"

Good question Mike.

How to Reduce Your Scripts

In Phoenix Viewer, you can right click on a item on your avatar, then menu [More ▸ S. Count]. For example, for my gun it reports “Scripts Counted: 11 [512K]”

Official Viewer from Linden Labs doesn't have that menu.

If you carefully go thru all items you are wearing, including every attachment, i think it should adds up to whatever some sim's script counters is reporting. Though, this is tricky, as some attachment are invisible or hard to find or able to click on.

How Much Memory Does a Script Use?

In the older days (pre-MONO script engine; before 2008-08), each script uses 16KiB of memory (KiB = kibibyte = 1024 bytes). With Mono today, each script uses 64KiB. (i heard that the plan was that each script will have variable memory allotted for each script, depending on need, but apparently this doesn't seem to have happened. It is not clear to me whether each mono script gets fixed 64KiB or it may grow.)

In your script, you can find the memory usage by the function “llGetFreeMemory”.

How to Write a Script Counter?

Here's the key elements.

Following is a basic example of using “llGetObjectDetails”.

// 2011-05-04
// http://xahlee.org/

// put the script in a prim. Then, click the prim, it'll report your script usage.

 default
 {
     state_entry()
     {
         llSetText("Touch me to see your script use.", <1,0,0>, 1);
     }

     touch_start(integer num_detected)
     {
         key agentId = llDetectedKey(0);
         string agentName = llDetectedName(0);

         list scriptUseInfo = llGetObjectDetails( agentId, [OBJECT_TOTAL_SCRIPT_COUNT,OBJECT_SCRIPT_MEMORY]);

         string mytext = agentName + " is hogging " + llList2String(scriptUseInfo, 0) + " scripts resource & using " + llList2String(scriptUseInfo, 1) + " memory!";

         llSay(0, mytext);
     }
 }

Put the script in a prim. Click the prim, then it'll print for example:

[02:37]  Xah Script Counter v0.2: Xah Toll is hogging 32 scripts resource and using 1753088 memory!

PS: Super thank you to Mike for much donations.

Reference