Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Water On and Off and opening drawers.

Kornscope Komachi
Transitional human
Join date: 30 Aug 2006
Posts: 1,041
10-17-2006 01:40
How would I turn a tap on and off?
Like on a vanity unit, somehow click on the tap handle and the water come out of the spout. Click again to stop. I'm guessing one would talk to the other? Two different prims.
If someone could point me to an example, that would be helpful. I check the wiki but don't know what to look for.
And an opening/closing drawer example or script.

Thanks very much
_____________________
SCOPE Homes, Bangu
-----------------------------------------------------------------
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
10-17-2006 06:54
If the prims in question are linked into single object, you could try to send out signal to spout prim using llMessageLinked() call, initiated by something like touch_start() event in script placed in the tap prim. This signal would be received by script placed in spout prim which could then accordingly set or disable water done either with llParticleSystem() or with simple textured cylinder prim shown or hidden with llSetAlpha()

If the prims are not linked, it's possible to use llSay() or somilar way of communication instead, to trigger the same effect.

For details on these functions, check out the LSL wiki page at http://www.lslwiki.com/lslwiki/wakka.php?wakka=HomePage
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-17-2006 09:43
Sliding drawer script that I created about a yr ago. Its well due an overhaul but feel free to use it as you like.

The following scriopt should go in each drawer prim.

CODE
// Sliding drawer script.
// Originally based on JohnG Linden's Sliding Door Script modified by Cutter Rubio
// Altered to work as a linked prim.


// displacement when open
float fOffset =-0.5;
// NOTE: if you want it to open right, you can either rotate it 180 degrees
// around the Z axis or change this to <1.5, 0.0, 0.0>
vector gRootPos = <0.0, 0.0, 0.0>;
vector gActualPos = <0.0, 0.0, 0.0>;
vector gOpenPos = <0.0, 0.0, 0.0>;
vector gClosedPos = <0.0, 0.0, 0.0>;

integer iLinkNumber = -1;


GetPosition()
{
gRootPos = llGetRootPosition();
gActualPos = llGetPos();
// Linked Prims work in offsets from root.
gClosedPos = gActualPos - gRootPos;
gOpenPos = gClosedPos;

gOpenPos.y += fOffset;
iLinkNumber = llGetLinkNumber();
}

default
{
on_rez(integer arg) { llResetScript(); }

state_entry()
{
// no physics until we need to open/close
llSetStatus(STATUS_PHYSICS, FALSE);
// but set proper values here anyway
llSetBuoyancy(1.0);
}

link_message(integer sender, integer channel, string data, key id)
{
iLinkNumber = llGetLinkNumber();
if(channel == iLinkNumber)
{
GetPosition();
//state door_opening;
state door_open;
}
}

}

state door_closed
{
on_rez(integer arg) { llResetScript(); }

state_entry()
{
llSetStatus(STATUS_PHYSICS, FALSE);
// enforce proper location
llSetPos(gClosedPos);
}

link_message(integer sender, integer channel, string data, key id)
{
iLinkNumber = llGetLinkNumber();
if(channel == iLinkNumber)
{
GetPosition();
//state door_opening;
state door_open;
}
}

}

state door_open
{
on_rez(integer arg) { llResetScript(); }

state_entry()
{
llSetStatus(STATUS_PHYSICS, FALSE);
llSetPos(gOpenPos);
}


link_message(integer sender, integer channel, string data, key id)
{
iLinkNumber = llGetLinkNumber();
if(channel == iLinkNumber)
{
state door_closed;
;
}
}

}




The following script goes into the base /root object.
CODE

default
{
touch_start(integer total_number)
{
// llSay(0, "Touched.");
integer i;
for(i =0; i<= total_number;i++)
{
integer linknum = llDetectedLinkNumber(i);
//Only respond to linked prim touches.
if(linknum > 1)
{
string strText = (string)linknum;
llMessageLinked(linknum, linknum, "", "");
//llOwnerSay("Sending Message to Prim " + strText);
}
}
}
}


like I said it was all written a long time ago when I was still jsut starting out with LSL.
I'm pretty it could all be rewriiten to only use one script but have never bothered doing so.
Kornscope Komachi
Transitional human
Join date: 30 Aug 2006
Posts: 1,041
Thanks
10-18-2006 00:24
for your efforts. I'll be off to give those ideas a try. If I can get something going I can (might) see whats going on and learn a little more. Thanks again.
_____________________
SCOPE Homes, Bangu
-----------------------------------------------------------------
Kornscope Komachi
Transitional human
Join date: 30 Aug 2006
Posts: 1,041
I just don't get it.
10-19-2006 01:35
Obviously I have no idea what I'm doing. I spent several hours going over this. It was relatively easy to get a box to go invisible with this...

CODE
CODE

default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}

touch_start(integer total_number)
{
llSay(0, "Touched.");
llSetAlpha(0.0, ALL_SIDES); // set entire prim 100% invisible.
}
}


But finding how to get the second click working. This is what I was doing..

CODE


default
{
state_entry()
{
llSay(0, "Invisible!");
}
touch_start(integer total_number)
{
llSay(0, "Touched.");
llSetAlpha(0.0, ALL_SIDES); // set entire prim 100% invisible.
}

}
listen (string message)
{
if (message == "Invisible")
{
llSetAlpha(1.0, ALL_SIDES); // set entire prim 100% visible.
}


I missed the scripting 101 last week so have to wait for the next one. It's no good starting at 103. I desparately need help. Mental help.
_____________________
SCOPE Homes, Bangu
-----------------------------------------------------------------
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-19-2006 03:51
Prims can't listen to themselves.

Something like this might help:
CODE

integer visible=TRUE;
default
{
state_entry()
{
llSetAlpha(1.0, ALL_SIDES);
}
touch_start(integer num)
{
if(visible)
{
llSetAlpha(0.0, ALL_SIDES);
} else
{
llSetAlpha(1.0, ALL_SIDES);
}
visible=!visible;
}
}


There are other ways to do this, but this should help. Not tested in world, and I'm on painkillers, so I'm not thinking 100% straight, even for something this short.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-19-2006 06:05
Hey Kornscope, welcome to the world of scripting. What Eloise posted works just fine, but to help you along you path I wanted to point out a couple of things. You did a good job of trying to use llOwnerSay to debug your script. But you had a listen in there when you had never setup a listener. And there was nothing to listen to anyway. You can't listen to the script that the listener is, as she pointed out and you can't listen to a touch anyway.

To post script here in the forum, it is more readable if you read the sticky up top and post it this way with no spaces in there;

Before script; [ PHP ]
After script [ / PHP]

Finally there are many ways to script something and get the same results. You could script your's sometime where instead of touch it would turn invisible by chat comands. It would be good practice. Also wanted to show another way of doing the same thing with states instead:

CODE

default {
touch_start(integer num_detected) {
llSetAlpha(0.0, ALL_SIDES);
state visible;
}
}
state visible{
touch_start(integer num_detected) {
llSetAlpha(1.0, ALL_SIDES);
state default;
}
}

Good luck and have fun!
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Kornscope Komachi
Transitional human
Join date: 30 Aug 2006
Posts: 1,041
Thanks team,
10-19-2006 19:32
( Excuse: Just couldnt remember where I saw that insert PHP stuff.)
Gee, that was easy... if ya know how.

Thank you all for your help, I will endevour to get it happening without asking stupid questions. U See, I can build and config a Linux PC in no time; have created a thousand web pages but can't create a line of code and never wanted to, until now.

BTW... Here's cheers to the millionth citizen.
_____________________
SCOPE Homes, Bangu
-----------------------------------------------------------------