Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

discussion: 1 prim double sliding glass door

Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
04-04-2007 16:45
From: sirhc DeSantis
just how bad are open listens in terms of performance?



A "Listen" will respond to anything 'said' on the channel it is listening to. Therefore, if an object is listening on channel 0 (public chat), quite a few events can fire in rapid succession during a conversation.

My favorite example is with weaponry in RP sims. For some reason, quite a few weapons-makers script their weapons to respond to commands from public chat...

Imagine 5 people standing around talking...each wearing a weapon. EVERY time someone says something...all 5 of those weapons process an event. Is it any wonder that so many RP sims are bogged down with script lag? Add to that a certain ultra-popular slave collar that listens on a public chat...and you have sims crawling with script lag, because everything anyone says is processed by some 20+ scripts all the time.

Now...if you took these same scripts and stuck 'em in a sim where no one ever said anything, they wouldn't cause any script lag at all...

...so...I guess the answer is 'depends on how frequently people talk'.
_____________________
--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.
sirhc DeSantis
Registered User
Join date: 8 Jan 2007
Posts: 60
guilty as charged
04-04-2007 16:51
i have to wear that collar and it can get damned embarrasing - is there a list where people can register the channels they are using for script comms?
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
04-05-2007 07:14
From: sirhc DeSantis
I just tried this and as new to scripts will try to take it apart to learn. awesome example though and thx for posting it. question for previous poster Learjeff - just how bad are open listens in terms of performance?


What Kenn said. :)

Expanding on that a bit:

The most "open" listen is like this:

listen(0, NULL_KEY, "", "";);

This means the script will be awaken any time anyone says anything within hearing range of the object. Now, if only one script in a busy club does this, it's no problem. But imagine if EVERY script in the room and in people's attachments and HUDs did! That's why this is the cardinal sin for script performance, even if the thing being done is very efficient (e.g., one string comparison and then quit, in most cases). I'm not sure about this, but I suspect that this is one of the causes of chat lag in a sim that otherwise seems fine. (I would also expect script lag in this case.) The sim has to do a lot of processing for each chat message, so they all get delayed a bit.

Now let's consider a few variations and see how they look in terms of performance. I will be making some assumptions, but I'm assuming the LL guys are pretty clever about this kind of thing, and I have reason to believe that they are. First, let's use a nonempty string for the last argument. I bet what the server does is hash the string into an index and save info about the script's listen in a location accessed using that index. Each time someone chats, their chat text is hashed the same way and the resulting value is used as an index to see if any scripts are listening for that string (or any string that hashes to the same value). Usually, there isn't, so no scripts are awaken. And this probably happens whether there are listens or not.

Unfortunately, a listen with a nonempty message parameter is of limited usefulness. It's fine for a simple object that only has one or two commands, or one where the command brings up a menu. But it's probably not a good idea to have a script that has dozens of commands issue a listen for each one. That uses memory on the server and takes more time whenever entering the state with all those listens. Still, if an object has to respond to chat from everyone, it's the best option. Of course, responding to a touch would be better, when possible. In that case the object's script is only run when someone specifically interacts with that object.

Now let's use the owner ID (or any specific user's key) rather than NULL_KEY, with an empty message parameter. In this case, the script is only awoken when the the owner chats. That's far better than when anyone chats, unless the person has a large number of objects that do this.

There is no registrar for chat channels. For communications between scripts/objects, very large and apparently random (and perhaps negative) numbers should be used, minimizing the odds of unrelated scripts using the same channel. With 4 billion possibilities, the odds are quite good.

For menus (llDialog), it's best to select a random number in the range that fits in a 32-bit signed number (ideally avoiding channels between 0 and 1000 or so) and use that channel for listens, again to minimize collisions between scripts. However, it's important to do the math for any script where you expect to have lots of objects within hearing range. By lots, I mean hundreds, so this isn't a typical concern.

But as an example, consider a room with 30 people in it. What are the odds that two people in the room have the same birthday? Well over 50%, as it turns out. The 50% mark is about 22 people, IIRC. Well, I haven't done the math, but if I were to have hundreds of the same script in an area using random chat channels, with possibility of crosstalk, I would do so. My guess is we'd be safe up to nearly 1000 or so, but these things are very non-intuitive so I'm not confident about that.

Note that this last bit concerns reliability, not performance.

HTH
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-05-2007 14:13
Just for clarification, the most open listen is actually llListen(0, "", NULL_KEY, "";); or llListen(0, "", "", "";); - you've got to give it an integer channel value, not a string otherwise the compiler throws a hissy fit. Although NULL_KEY and "" are not directly equivalent, in this function they work that way.

In theory llListen(-5005, "", "", "";); is equally open, but in practise far less demanding on the sim, there's just less chat on channel -5005.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
04-05-2007 21:44
Thanks for the correction. I've edited my text above accordingly.
Kamilion Schnook
Registered User
Join date: 26 Jan 2006
Posts: 18
04-06-2007 01:14
Here's a handy snippet I've been using for a long while now.

dialogChannel = (integer)llFrand(DEBUG_CHANNEL) * -1; // Pick a random negative channel to listen for dialog events on.

Hope it helps someone out ;)
_____________________
During his last shootout, police said "Come out, you're surrounded!"
He replied, "I'm not surrounded, I just have more targets now!"

Old enough to know better, young enough not to care.
Turnoffs: The blue wire. (or was it the yellow?)

It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds. --Samuel Adams
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
05-09-2007 21:31
I have been trying to alter this to allow anyone who belongs to the same group to get access. I am not having much luck...
I have tried this:

key id = llDetectedKey(0);
if ( llSameGroup(id)

but that does not work.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
05-09-2007 22:16
Which did you mean llSameGroup always returned "TRUE" or "FALSE"? If "FALSE", did the person really activate the group tag?
_____________________
:) Seagel Neville :)
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
05-10-2007 05:56
This works; we do it all the time. First, I assume this is in a touch event. llDetectedKey() doesn't work for listen(). Second, as mentioned above, the person touching has to have the group activated.
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
05-10-2007 08:15
I am new and scripting so I am sure I am missing something obvious.
Here is the script and where I modified.
We tested it with an Alt that has the tag showing and not showing and both times they were able to open. Thanks for your help

//Original 1 prim double sliding glass door was made by Seagel Neville as public domain, Nov 2006
//Modified by Kevin Carbonaro (SL: Kevin Ballinger) 8 March 2007
//
//Fixes:
//-FIX - Now resetting the script will not re-position, scale, and rotate the object to some pre-defined numbers.
//
//To Do:
//-Improve Smoothness of Door Opening and Closing Animation.
//-Use a Dialog to Code Lock the door.

integer pitch = 5; //Steps for the door to take to open and close. More Steps will make the door open and close more slowly.
float TimeInterval = 6.0; //Seconds to keep the door open.
integer TouchFlag;
integer Holding;
integer SecureFlag;

Open()
{
TouchFlag = TRUE;
llTriggerSound("de7ac1a3-f31b-e1a4-5a21-5b9907921bf1", 1.0);
integer i;
for(i = 0; i < pitch + .5; i++)
{
llSetPrimitiveParams([PRIM_TYPE, 0, 0, <0.000000, 1.000000, 0.000000>,
0.949000, <0.000000, 0.000000, 0.000000>, <;(float)i/pitch, 1.000000, 0.000000>,
<0.000000, 0.000000, 0.000000>]);
}
llSetTimerEvent(TimeInterval);
}

Close()
{
llSetTimerEvent(0);
TouchFlag = FALSE;
llTriggerSound("44f32d82-8604-1f29-37c9-a35baec646ee", 1.0);
integer i;
for(i = pitch - 1; i >= 0 ; i--)
{
llSetPrimitiveParams([PRIM_TYPE, 0, 0, <0.000000, 1.000000, 0.000000>,
0.949000, <0.000000, 0.000000, 0.000000>, <;(float)i/pitch, 1.000000, 0.000000>,
<0.000000, 0.000000, 0.000000>]);
}
}

TouchOpen()
{
if(TouchFlag == FALSE)
{
Open();
}
else
{
Close();
}
}

CollideOpen()
{
if(TouchFlag == FALSE)
{
Open();
}
else
{
llSetTimerEvent(TimeInterval);
}
}

Init()
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_GLASS, PRIM_SIZE, llGetScale(),
PRIM_TYPE, 0, 0, <0.0, 1.0, 0.0>, 0.949, <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_ROTATION, llGetRot(),
PRIM_COLOR, ALL_SIDES, <0.0, 0.0, 0.5>, 0.5, PRIM_POSITION, llGetPos() + (<0, 0, 0> * llGetRot()),
PRIM_TEXTURE, ALL_SIDES, "5748decc-f629-461c-9a36-a35a221fe21f",
<1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
}

default
{
state_entry()
{
Init();
}
changed(integer change)
{
if(change & CHANGED_OWNER)
{
llResetScript();
}
}
touch(integer total_number)
{
key id = llDetectedKey(0); // MY MODIFY HERE
if (llSameGroup(id))

// if(llDetectedKey(0) == llGetOwner())
{
Holding++;
if(Holding == 50)
{
if(SecureFlag == FALSE)
{
llOwnerSay("Door Locked";);
SecureFlag = TRUE;
}
else
{
llOwnerSay("Door Unlocked";);
SecureFlag = FALSE;
}
}
}
}
touch_end(integer total_number)
{
Holding = 0;
if(SecureFlag == FALSE)
{
TouchOpen();
}
else
{
key id = llDetectedKey(0); // MY MODIFY HERE
if (llSameGroup(id))

//if(llDetectedKey(0) == llGetOwner())
{
TouchOpen();
}
else
{
llWhisper(0, "Sorry, this door is locked.";);
}
}
}
collision_start(integer num_detected)
{
if(SecureFlag == FALSE)
{
CollideOpen();
}
else
{
key id = llDetectedKey(0); // MY MODIFY HERE
if (llSameGroup(id))

// if(llDetectedKey(0) == llGetOwner())
{
CollideOpen();
}
else
{
llWhisper(0, "Sorry, this door is locked.";);
llSleep(5.0);
}
}
}
timer()
{
Close();
}
}
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
05-10-2007 10:57
Is your door set as the group? Make sure that Edit/General tab/Group.
_____________________
:) Seagel Neville :)
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
05-10-2007 11:45
Nichiren, next time please enclose your code between "[php ]" "[/php]" tags (omit the space).

Thanks :)
Jeff
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
05-10-2007 16:52
sorry about the php..will do next time.

Yes. the door was created with me wearing the tag...I just dbl checked and it does who it bein g in the group
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
05-11-2007 04:52
I made sure that your modified script worked well, though the init shape was different.
Please make clear how it didn't work.
Non-group tag people were able to lock the door? Or even the group tag people were unable to lock it? Even though the door was locked, some people were able to open it?
_____________________
:) Seagel Neville :)
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
05-11-2007 08:28
From: Seagel Neville
I made sure that your modified script worked well, though the init shape was different.
Please make clear how it didn't work.


dpb: currently ANYONE can touch or collide into it and it opens...does not matter if they are wearing a group tag or not.

From: Seagel Neville
Non-group tag people were able to lock the door? Or even the group tag people were unable to lock it?


dpb: not sure what this means. in its current state the door is NEVER locked. And I don't really know anyway to get it locked. Even as owner I can't seem to lock it. maybe I dont understand how that part works.


From: Seagel Neville
Even though the door was locked, some people were able to open it?


dpb: door is not locked (from what I can tell). It always opens via a collide or touch.

What I was hoping to accomplish was to have a door where group members can touch or collide into it and it opens up. For all other avatars the door would not open. I am playing with the script. I believe I need to use the DetectedGroup. here is a snippet. I have something like this working in another object (not a door).

question...are you saying that there is a way to manually lock the door with the script posted above?? I will go back and try that. I would prefer to just let all group members in and keep non-group members out.

CODE

touch(integer total_number)
{
integer i;

for ( i = 0 ; i < total_number ; ++i )
{
key id = llDetectedKey(i); // MY MODIFY HERE
if ( id == llGetOwner() || (llDetectedGroup(i) && ! llSameGroup(NULL_KEY)) )

{
Holding++;
if(Holding == 50)
{
if(SecureFlag == FALSE)
{

llSay(0, "Sorry, " + llDetectedName(i) + ", this object may only be used by group members. If you are a member of the group, switch your active group tag to it.");
SecureFlag = TRUE;
}}
else
{
llSay(0,"Door Unlocked");
SecureFlag = FALSE;
}
}
}
}
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
05-11-2007 08:46
This door has a lock function. When you touch the door and keep holding it for a while, the lock is activated. It takes 50 counts. If you want to lock it earlier, reduce the number.

You changed the condition that who could lock it and who could open it even when it was locked. I guess you are telling that everybody can open it even though you have not locked it yet.
_____________________
:) Seagel Neville :)
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
05-11-2007 09:19
OH!! got it...I see...and it works great! thanks
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
05-11-2007 10:52
I should post a version that is not so hoggy.

Be aware that while you're holding the mouse button down, this script dramatically increases lag on the server, far more than any open listen.

SO: don't use this script in a very busy sim, and don't use lots of these doors.

Regards,
Jeff
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
05-11-2007 15:32
Setting the lock on and off should be used just once at the first time or most may not use it because the lock in SL is all bells and whistles.

But I agree with you fundamentally. Changing shape by for-loop uses a lot of cpu power and it is not also seen smooth. :o
_____________________
:) Seagel Neville :)
Amanda Shinji
Registered User
Join date: 10 Dec 2006
Posts: 3
07-27-2007 18:05
Is there any way to add a function so that only listed people can use the door? That would be absolutely perfect for a build I'm working on... :D
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
Listed people?
07-29-2007 11:32
Prepare a notecard and put down names of listed people like this.
CODE
Amanda Shinji
Seagel Neville

And use this script.
CODE
//1 prim double sliding glass door was made by Seagel Neville as public domain, Nov 2006
integer pitch = 5;
float TimeInterval = 3.0;
integer TouchFlag;
integer Holding;
integer SecureFlag;

string gName;
integer gLine;
key gQueryID;
list autholizedList;

Open()
{
TouchFlag = TRUE;
llTriggerSound("de7ac1a3-f31b-e1a4-5a21-5b9907921bf1", 1.0);
integer i;
for(i = 0; i < pitch + 1; i++)
{
llSetPrimitiveParams([PRIM_TYPE, 0, 0, <0.000000, 1.000000, 0.000000>,
0.949000, <0.000000, 0.000000, 0.000000>, <(float)i/pitch, 1.000000, 0.000000>,
<0.000000, 0.000000, 0.000000>]);
}
llSetTimerEvent(TimeInterval);
}

Close()
{
llSetTimerEvent(0);
TouchFlag = FALSE;
llTriggerSound("44f32d82-8604-1f29-37c9-a35baec646ee", 1.0);
integer i;
for(i = pitch - 1; i >= 0 ; i--)
{
llSetPrimitiveParams([PRIM_TYPE, 0, 0, <0.000000, 1.000000, 0.000000>,
0.949000, <0.000000, 0.000000, 0.000000>, <(float)i/pitch, 1.000000, 0.000000>,
<0.000000, 0.000000, 0.000000>]);
}
}

TouchOpen()
{
if(TouchFlag == FALSE)
{
Open();
}
else
{
Close();
}
}

CollideOpen()
{
if(TouchFlag == FALSE)
{
Open();
}
else
{
llSetTimerEvent(TimeInterval);
}
}

Init()
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_GLASS, PRIM_SIZE, <2.0, 2.7, 0.01>,
PRIM_TYPE, 0, 0, <0.0, 1.0, 0.0>, 0.949, <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_ROTATION, <0.7, 0, 0, 0.7>,
PRIM_COLOR, ALL_SIDES, <0.0, 0.0, 0.5>, 0.5, PRIM_POSITION, llGetPos() + (<0, 0, 1.1> * llGetRot()),
PRIM_TEXTURE, ALL_SIDES, "5748decc-f629-461c-9a36-a35a221fe21f",
<1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
}

default
{
state_entry()
{
Init();
}
changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
if(llGetInventoryType(llGetInventoryName(INVENTORY_NOTECARD, 0)) != -1)
{
gName = llGetInventoryName(INVENTORY_NOTECARD, 0);
gLine = 0;
autholizedList = [];
gQueryID = llGetNotecardLine(gName, gLine);
}
}
}
touch(integer total_number)
{
if(llDetectedKey(0) == llGetOwner())
{
Holding++;
if(Holding == 50)
{
if(SecureFlag == FALSE)
{
llOwnerSay("Secured mode has been ON");
SecureFlag = TRUE;
}
else
{
llOwnerSay("Secured mode has been OFF");
SecureFlag = FALSE;
}
}
}
}
touch_end(integer total_number)
{
Holding = 0;
if(SecureFlag == FALSE)
{
TouchOpen();
}
else
{
if(llDetectedKey(0) == llGetOwner() || llListFindList(autholizedList, [llDetectedName(0)]) != -1)
{
TouchOpen();
}
else
{
llWhisper(0, "Sorry, this door is beeing locked.");
}
}
}
dataserver(key query_id, string data)
{
if (query_id == gQueryID)
{
if (data != EOF)
{
autholizedList += data;
++gLine;
gQueryID = llGetNotecardLine(gName, gLine);
}
}
}
collision_start(integer num_detected)
{
if(SecureFlag == FALSE)
{
CollideOpen();
}
else
{
if(llDetectedKey(0) == llGetOwner() || llListFindList(autholizedList, [llDetectedName(0)]) != -1)
{
CollideOpen();
}
else
{
llWhisper(0, "Sorry, this door is beeing locked.");
llSleep(5.0);
}
}
}
timer()
{
Close();
}
}

Note: Put the script into the prim before the notecard. You can also add names on the list in the prim.
_____________________
:) Seagel Neville :)
Meetmy Destiny
Registered User
Join date: 5 Dec 2007
Posts: 5
Lock on door?
02-04-2008 23:36
Hi Seagel,

i love this script,
makes my house such much better,
but i miss a normal lock not when people bump into a several times,
just like you lock your rl home.
I trieds several doorlocks but they al work with a chatchannel and i can't find that in the script.
Can you help me out to make it more secure.

greetings Meetmy
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
02-05-2008 00:03
Press the door by left clicking until it says, "Secured mode has been ON". It toggles. :o
_____________________
:) Seagel Neville :)
Meetmy Destiny
Registered User
Join date: 5 Dec 2007
Posts: 5
02-08-2008 00:45
How many times?
i keep clicking.

so for now i put the sript turned of till i can lock it,
the upperdoor is open,
se if you like in my profile **My place.

greetings Meetmy
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
02-08-2008 01:07
From: Meetmy Destiny
How many times?
i keep clicking.

so for now i put the sript turned of till i can lock it,
the upperdoor is open,
se if you like in my profile **My place.

greetings Meetmy

Not keep clicking, but keep pressing for 10 seconds or so!
_____________________
:) Seagel Neville :)
1 2 3