Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Simple Show/Hide Script

Sean Playfair
Registered User
Join date: 5 Jul 2004
Posts: 3
10-22-2006 20:06
I spent forever looking for a script with just a show hide feature for the objects I've started building, but had no luck here in the forum, or in game. So with the little programming experience I have, I looked up the SL scripting site and put together this little bit of script that will let you hide and show your poseballs or other objects with a simple channel check and typing either "show" or "hide". I'm sure others are better, and many are available in some circles, but I just decided to post this for anyone else that needed a quick, usefull script.



CODE

show()
{
llSetAlpha(1.0, ALL_SIDES);
}

hide()
{
llSetAlpha(0, ALL_SIDES);
}

default
{
state_entry()
{
// listen on channel zero for any chat spoken by the object owner.
llListen(1,"",NULL_KEY,"");
}

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

message = llToLower(message);

if(message == "show")
{
show();
return;
}
if(message == "hide")
hide();
}
}







You can change the channel to listen for to every channel by changing llListen(1,"",NULL_KEY,"";) to llListen(0,"",NULL_KEY,"";). You can also change the "1" to any channel number you wish. Just copy and past into a new script and make any changes. Enjoy.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
10-22-2006 21:02
/15/85/144919/1.html
_____________________
i've got nothing. ;)
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
10-22-2006 21:53
I'm bored, so I made an alternate version which might be slightly more efficient... It could be improved further by limiting the listens to only the owner using llGetOwner() in place of the NULL_KEY, and even better (yet slightly more limiting) would be to replace the empty string at the end of the listen function, "", with the specific word you're listening for, such as "hide" or "show". Doing that will eliminate the need for an if statement under each listen event.. only the state calls will be needed. However, that requires the owner to know to use lowercase.

Those are just tips as you start down the road to scripting goodness.

CODE

integer channel = 1;

default {
state_entry() {
llSetAlpha(1.0, ALL_SIDES);
llListen(channel, "", NULL_KEY, ""); // listen on channel <channel>
}
listen(integer channel, string name, key id, string message) {
if (llToLower(message) == "hide") state hide;
}
}

state hide {
state_entry() {
llSetAlpha(0.0, ALL_SIDES);
llListen(channel, "", NULL_KEY, "");
}
listen(integer channel, string name, key id, string message) {
if (llToLower(message) == "show") state default;
}
}
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-22-2006 22:28
CODE

default
{
state_entry()
{
llListen(90, "", NULL_KEY, "");
}

listen(integer channel, string name, key id, string message)
{
if (message == "show") llSetAlpha(1.0, ALL_SIDES);
else if (message == "hide") llSetAlpha(0.0, ALL_SIDES);
else return;
}
}
Ishtara Rothschild
Do not expose to sunlight
Join date: 21 Apr 2006
Posts: 569
10-23-2006 04:03
/Edit: removed a wrong information

Btw, Osgeld: what purpose does the return function have at the end of the listen event? I'm not much of a programmer; I'd assume that it returns anyway as soon as the event ends? Or does the "else return" reduce the number of possibilities for the if...else function?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-23-2006 09:09
From: Ishtara Rothschild
It's a little more performant when the script listens to specific words only:


Have you got evidence for this? It strikes me as unlikely... I'd have expected more listeners, even if well filtered, to slow things down in terms of the sim, and since you've got to do a string comparison in the script to give no benefits there either.

Where it *might* be faster is if you have llListen(89, "", llGetOwner(), "show";); and llListen(90, "", llGetOwner(), "hide";);

and use
if(channel==89)... else... in the listen event, but I'd still like to see the numbers for the hit on the sim to be sure.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Ishtara Rothschild
Do not expose to sunlight
Join date: 21 Apr 2006
Posts: 569
10-23-2006 13:43
Hm... someone once told me that llListen should be used with filtering criteria whenever possible. So it's a larger number of listeners that lags a sim, not unfiltered listening? As I said, I'm not that much of a scripter :)
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-23-2006 14:32
I agree with some filtering... the channel always, llGetOwner() if possible.

I'm pretty sure the extra listen with the message filter for two messages adds load though. If you had a message such as "balls" which toggled them between hidden and showing, then filtering for that too is probably worth it.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-23-2006 18:18
From: Ishtara Rothschild

Btw, Osgeld: what purpose does the return function have at the end of the listen event? I'm not much of a programmer; I'd assume that it returns anyway as soon as the event ends? Or does the "else return" reduce the number of possibilities for the if...else function?


in this case, if someone says anything but "show" or "hide" the event will exit

yea the event will do it anyway, but it allows me to show a full if loop, and your more aware of the return function

Or

i started to write an error message and just never did it

your choice :D
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-23-2006 18:27
oh llListen filters, if your using a channel you have 1 layer of filtration (which is better than none) the major problem with listens is when they are wide open on channel 0

you can imagine the stackup of events and cpu power this can eat up in a livley scocial setting
30 avs all chatting and 1 script taking it all in looking for "show" and "hide" *shudder*

i usually use 1 channel for everything and if possible the owner

if you use mutiple states you could toggle the 2 listeners on and off, that way state show would only listen for "hide" and hide would only listen for "show"
Ishtara Rothschild
Do not expose to sunlight
Join date: 21 Apr 2006
Posts: 569
10-23-2006 18:45
Learned something again :) thanks for clarifying this. I'll work with 1 listener from now on whenever possible.
Cristalle Karami
Lady of the House
Join date: 4 Dec 2006
Posts: 6,222
02-22-2007 17:12
I've been using a variant of Osgeld's script and found that the filter is not working. All I did is add an extra listen filter for someone else other than the owner to activate the script.

However, I found out tonight that anyone speaking on the channel can trigger the show/hide. What is wrong here?

From: someone
default


{
state_entry()
{
llListen(91, "", llGetOwner(), "";);
llListen(91, "", "Extra Name", "";);
}

listen(integer channel, string name, key id, string message)
{
if (message == "hide";)
{
llSetTexture("GlassMottled (gnubie)",1);
llSetTexture("curtainwindow101_inside",3);
llSetAlpha(1.0,1);}

else if (message == "show";)
{ llSetTexture("curtainwindow101high",1);
llSetTexture("curtainwindow101high_inside",3);
//the texture shown in the default state is "curtainwindow101high" on the outside, and "curtainwindow101high_inside" on the inside.
llSetAlpha(1.0,1);}
//1.0 shows all of a texture, 0.0 shows none
//llScaleTexture(24,24, ALL_SIDES);//adjusts texture scale if needed.
else return;
}
}
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
02-22-2007 17:17
You put the "other name" in the UUID(key) field for the listen, rather than the NAME(string) field.

My version:
CODE

integer ch = 1;

default {
state_entry() {
//llListen(ch, "", llGetOwner(), "hide"); // owner only version
llListen(ch, "", "", "hide"); // everyone version
llSetAlpha(1.0, ALL_SIDES);
}
listen(integer c, string n, key id, string msg) {
state hide;
}
}

state hide {
state_entry() {
//llListen(ch, "", llGetOwner(), "show"); // owner only version
llListen(ch, "", "", "show"); // everyone version
llSetAlpha(0.0, ALL_SIDES);
}
listen(integer c, string n, key id, string msg) {
state default;
}
}
Cristalle Karami
Lady of the House
Join date: 4 Dec 2006
Posts: 6,222
02-22-2007 17:30
Thanks for the quick reply DoteDote. Appreciate it!