Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Auto close for curtain script - need help

Leila Juneberry
Registered User
Join date: 25 Mar 2009
Posts: 5
06-15-2009 12:57
Hi.

I found this simple and great curtain script on sl wiki. However, I want my curtains to automatically close after a while and this feature is not in the script.

Could anyone help me with this ? Thanks so much!

--------------------
vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?
//The one with the higher (local) coordinate?
float min = 0.2; //The minimum size of the prim relative to its maximum size
integer ns = 10; //Number of distinct steps for move/size change


default {
state_entry() {
offset *= ((1.0 - min) / ns) * (offset * llGetScale());
hi_end_fixed -= 0.5;
}

touch_start(integer detected) {
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
}
}
-------------------------
Ultralite Soleil
Registered User
Join date: 31 Aug 2006
Posts: 108
06-15-2009 14:51
What have you tried so far, and what problems did you have?
Leila Juneberry
Registered User
Join date: 25 Mar 2009
Posts: 5
06-15-2009 18:05
I have no experience with LSL, this is all brand new for me. There are a few script examples in the library (for doors) I looked at. They have those automatic closing features after a few seconds. This is what I would like to have in my curtains.

So I copied and pasted some of the code to the curtain script (hahaha, I know....) and it did not work (syntax error). So here I am and stuck :)
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
06-15-2009 21:18
From: someone

vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?
//The one with the higher (local) coordinate?
float min = 0.2; //The minimum size of the prim relative to its maximum size
integer ns = 10; //Number of distinc-t steps for move/size change

closed()
{
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;

}


default
{
state_entry()
{
offset *= ((1.0 - min) / ns) * (offset * llGetScale());
hi_end_fixed -= 0.5;
}

touch_start(integer detected) {
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
llSetTimerEvent(10.0);
}
timer()
{
closed();
llSetTimerEvent(0);
}
}


I didnt test it yet (downloading new viewer :s ) But this can give you a way to how _add a timer to your script.
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
06-16-2009 07:00
the only thing it seems to be missing is a toggle to know whether or not it's currently open/closed. if it's touched to close it, when the timer goes off, it will open it.

edit, here's what i got, it can probably be cleaned up some more, but it's too early for me

CODE

vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?
//The one with the higher (local) coordinate?
float min = 0.1; //The minimum size of the prim relative to its maximum size
integer ns = 15; //Number of distinc-t steps for move/size change
integer open = FALSE;

closed()
{
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
open = FALSE;
llSetTimerEvent(0.0);
}


default
{
state_entry()
{
offset *= ((1.0 - min) / ns) * (offset * llGetScale());
hi_end_fixed -= 0.5;
}

touch_start(integer detected) {
if(!open)
{
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
llSetTimerEvent(10.0);
open = TRUE;
}
else
{
closed();
}

}
timer()
{
closed();
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Leila Juneberry
Registered User
Join date: 25 Mar 2009
Posts: 5
06-16-2009 07:44
Thanks so much for the postings and your help. I will try both and post the results later today. :)
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
06-16-2009 07:54
Leila...

One of the tricky things about scripting is to specify exactly what you want. For example, "close after awhile" seems clear, but it could lead to many different interpretations. For example, it could mean close after the last person leaves the house, or it could mean close when the people in the house go to bed...

lee
_____________________
So many monkeys, so little Shakespeare.
Leila Juneberry
Registered User
Join date: 25 Mar 2009
Posts: 5
06-16-2009 11:05
Ruthven and Papalopulus, thanks so much. Both your scripts work excellent and I already put them in my curtains. I am very happy that this works so nice and exactly as I wanted.

Papalopulus script does not check if the curtain is open or not, so I used Ruthven's for my curtains. However, Papalopulus script could work great in a blanket...

Lee, yes, I agree. I meant to have them closed after a pre-set time and both scripts have that. I simply changed the seconds in the script.

Thanks, Leila