Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with visitor counter that stops working

Princess Ivory
SL is my First Life
Join date: 17 Jan 2007
Posts: 720
09-20-2007 11:51
I have a visitor counter that periodically and unexpectedly stops working. I have to open it up and reset it to get it to work again. This is a pain, and I often loss important figures from locations I am not always present at every day.

I'm using a free script. I think we made some minor changes to it, mostly in terms of text.
Could someone who is good with this kind of stuff take a look at the following script, and see if you notice an errors that would cause it to stop working periodically? Or is this just another Linden bug?

Thanks,
Princess Ivory

This is the exact content copied from the script:

// Original script taken from a freebie i found somewhere
//
// Modified to say a greeting to each visitor
// The greeting is held in th eobject description field
//
// All says have been changed to ownersays so to relieve channel 0 talk
// and keep the output private to the owner
//
// Touch_start section added to re-read the greeting if you change the description field
//
// Original Author unknown
// Mods by Adriana Caligari

string welcome;

// Global variables
list visitor_list;
float range = 20.0; // in meters
float rate = 1.0; // in seconds


// Functions
integer isNameOnList( string name )
{
integer len = llGetListLength( visitor_list );
integer i;
integer pos;
for( i = 0; i < len; i++ )
{
pos=llSubStringIndex(llList2String(visitor_list, i), ":**";) - 1;
if(llGetSubString(llList2String(visitor_list, i), 0, pos) == name )
{
return TRUE;
}
}
return FALSE;
}

init()
{
welcome = llGetObjectDesc();
llOwnerSay( "Visitor List Maker started...";);
llOwnerSay( "The owner can say 'help' for instructions.";);
llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
llListen(0, "", llGetOwner(), "";);
}
// States
default
{
state_entry()
{
init();
}
on_rez( integer param )
{
init();
}
touch_start( integer num )
{
welcome = llGetObjectDesc();
}

sensor( integer number_detected )
{
integer i;
for( i = 0; i < number_detected; i++ )
{
if( llDetectedKey( i ) != llGetOwner() )
{
string detected_name = llDetectedName( i );
if( isNameOnList( detected_name ) == FALSE )
{
llInstantMessage( llDetectedKey( i ), welcome + detected_name );
visitor_list += detected_name + ":** arrived at " + llGetTimestamp();
llOwnerSay ( detected_name + " has been added to your visitors list at " + llGetRegionName() );
}
}
}
}

listen( integer channel, string name, key id, string message )
{
if( id != llGetOwner() )
{
return;
}

if( message == "help" )
{
llOwnerSay( "This object records the names of everyone who" );
llOwnerSay( "comes within "+ (string)range + " meters." );
llOwnerSay( "Commands the owner can say:" );
llOwnerSay( "'help' - Shows these instructions." );
llOwnerSay( "'say list' - Says the names of all visitors on the list.";);
llOwnerSay( "'reset list' - Removes all the names from the list." );
llOwnerSay ( "TO change the greeting - change the object description and touch the object" );
}
else
if( message == "say list" )
{
llOwnerSay( "Visitor List:" );
integer len = llGetListLength( visitor_list );
integer i;
for( i = 0; i < len; i++ )
{
llOwnerSay( llList2String(visitor_list, i) );
}
llOwnerSay( "Total = " + (string)len );
}
else
if( message == "reset list" )
{
visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
llOwnerSay( "Done resetting.";);
}
}
}
_____________________
Princess Ivory
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
09-20-2007 12:00
I looks like if you don't periodically reset the list, it keeps growing and growing? So it could be it runs out of memory before you get there to reset it, and so stops working.

You could put a call to llGetFreeMemory in there, and if it gets too small (like down under 1000 bytes maybe), send a notification to the owner to get over there and reset it, or even just email the list to the owner, and reset itself.
Buffy Wilder
Registered User
Join date: 12 Jan 2007
Posts: 16
09-20-2007 12:31
Yes it will be running out of memory (only have 16K for stack/heap and code)

to make it more efficent you can replace the line

visitor_list += detected_name + ":** arrived at " + llGetTimestamp();

with

string newName = detected_name + ":** arrived at " + llGetTimestamp();
visitor_list = (visitor_list = []) + visitor_list + newName;


This is more memory efficient for adding things to lists (yes it looks evil but trust me it works :-) This will allow you to have more items in your list before it runs out of memory.

What you need to do as Princess suggested is to check how much memory you have left when you add a name to the list and either IM the owner to come and reset the list or have it automatically remove the first element(s) from the list.

Hope this helps

Buffy
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
09-20-2007 13:36
I say just send your visitor list to an external database that can track and monitor your visitor statistics over long periods of time, filter out repeat visitors, etc.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.