01-03-2004 15:54
Im currently working on a project that requires multi-script communication, and wanted an easy way to monitor each script's free memory without spamming the chat channel with "freemem == " messages, so I decided to use settext.

The problem with settext is that when each script calls it, the old text is erased, and the new text is displayed. This wasn't good for my purpose, because I wanted to know each script's memory simultaniously. In responce to that, I created a little script that would do what I want.

Here's the main manager script:
CODE

// Freemem displayer, utility script.

list scriptNames;
list scriptFreemems;

displayMems()
{
string text = "Freemems:\n";

integer i;
integer len = llGetListLength(scriptNames);
for(i = 0; i < len; i++)
{
string scriptName = llList2String(scriptNames,i);
integer scriptFreemem = (integer)llList2String(scriptFreemems,i);

text += scriptName + " " + (string)scriptFreemem + "\n";
}
llSetText(text,<0,1,0>,1.0);
}

debug(string message)
{
llSay(0,llGetScriptName() + " - " + message);
}

default
{
state_entry()
{
debug("default, state_entry()");
llSetTimerEvent(60);
}
link_message(integer sender, integer freeMem, string scriptName, key command)
{
if(command == "FREEMEM") // If wants to display freememory:
{
integer index = llListFindList(scriptNames,[scriptName]);
if(index > -1) // If already exists in directory...
{
// Replace old values with new ones:
scriptFreemems = llListInsertList(llDeleteSubList (scriptFreemems,index,index),[freeMem],index);
displayMems();
}
else // Add new script to list...
{
scriptNames += scriptName;
scriptFreemems += freeMem;
displayMems();
}
}
}
timer()
{
scriptNames = [];
scriptFreemems = [];
}
}


Here's the function that you put in each script you want to update:

CODE

updateFreeMemory()
{
llMessageLinked(LINK_SET,llGetFreeMemory(),llGetScriptName(),"FREEMEM");
}


Enjoy! :D

==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm