Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sliding door script help please,

Zarni Torok
Registered User
Join date: 22 Feb 2007
Posts: 5
03-09-2008 17:56
Hello, i am very new to scripting and mainly using/altering free etc scripts so bear with me please :)
I made a simple hud and wished to have it hidable by having it sliding off screen somewhat on touch.
I got a sliding door script, altered it to slide the right way for me etc, it works perfectly on the ground, but when i use it as a hud it slides to the right as i want, but if i touch it again it slides again to the right and not back to the starting place.
Every click just keeps moving it one way.
What should i do to let it know that its attached to me and to get it to do as it did when rezzed on the ground?
Any help would be much appreciated. thank you.

the script im using is //Sliding Door v4
//Works when linked
//by Kayla Stonecutter
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-09-2008 19:49
code?

I imagine it should look a bit like

llSetPos( offset );
offset = -offset;

that would reverse the direction on each touch.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Zarni Torok
Registered User
Join date: 22 Feb 2007
Posts: 5
03-10-2008 11:57
thank you for your reply, i didnt post the code as i didnt know if that was acceptable to do in this forum, will do now :)
I see the command offset is diffrerent than yours, n/s e/w etc, would adding the command you said break the script? well, i guess i have one way of finding out heh. thank you again for any help.

//Sliding Door v4
//Works when linked
//by Kayla Stonecutter

//How far in meters to travel in each direction. Two or all three can be used for angled movement
//NOTE: when linked, this is relative to the root prim
//Positive = move north, negative = move south
float NorthSouth = 0.5;
//Positive = move east, negative = move west
float EastWest = -0.0;
//Positive = move up, negative = move down
float UpDown = 0.0;

//The amount in seconds to stay open, set to 0 to not autoclose
float Timer = 0;

//Sound to play on open, either a UUID or a name in the door contents
//if a name, it must be exact. Leave at "" for no sound
string OpenSound = "";

//Volume to play open sound, 0.0 is same as no sound, 1.0 is max
float OpenVol = 0.0;

//Sound to play on close, either a UUID or a name in the door contents
//if a name, it must be exact. Leave at "" for no sound
string CloseSound = "";

//Volume to play close sound, 0.0 is same as no sound, 1.0 is max
float CloseVol = 0.0;


//misc variables
vector Pos;
vector Offset;
integer Open;
integer x;

default
{
state_entry()
{
Offset = <EastWest, NorthSouth, UpDown>;
}

touch_start(integer num)
{
for(x = 0; x < num; x++)
{
Open = !Open;
if(Open)
{
Pos = llGetLocalPos();
if(OpenSound != "";) llTriggerSound(OpenSound, OpenVol);
llSetPos(Pos + Offset);
llSetTimerEvent(Timer);
}else{
if(CloseSound != "";) llTriggerSound(CloseSound, CloseVol);
llSetPos(Pos);
llSetTimerEvent(0);
}
}
}

on_rez(integer param)
{
llResetScript();
}

moving_end()
{
if(Open)
{
Open = 0;
llSetTimerEvent(0.0);
}
}

timer()
{
if(CloseSound != "";) llTriggerSound(CloseSound, CloseVol);
llSetPos(Pos);
llSetTimerEvent(0);
Open = 0;
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-10-2008 17:25
here's my tweaks, to reduce overal code, and streamline the logic a bit, also included some notes on deleteing unused sections, and explanation comments.
CODE

//Sliding Door v4
//Works when linked
//by Kayla Stonecutter
//-- tweaked heavily by Void Singer Mar 10, 2008

//How far in meters to travel in each direction. Two or all three can be used for angled movement
//NOTE: when linked, this is relative to the root prim
//Positive = move north, negative = move south
float NorthSouth = 0.5;
//Positive = move east, negative = move west
float EastWest = -0.0;
//Positive = move up, negative = move down
float UpDown = 0.0;

//The amount in seconds to stay open, set to 0 to not autoclose
//-- delete next line if not using autoclose
float Timer = 0.0;

//-- begin sound section: delete to 'end sound section' if not using sounds

//Sound to play on open, either a UUID or a name in the door contents
// in quotation marks. if a name, it must be exact.
string OpenSound = "";

//Volume to play open sound, 0.0 is same as no sound, 1.0 is max
//-- setting this to 0.0 turns off open sounds
float OpenVol = 0.0;

//Sound to play on close, either a UUID or a name in the door contents
// in quotation marks. if a name, it must be exact.
string CloseSound = "";

//Volume to play close sound, 0.0 is same as no sound, 1.0 is max
//-- setting this to 0.0 turns off close sounds
float CloseVol = 0.0;

//-- end sound section

//misc variables
vector Offset;
integer Open;

//-- begin sound trigger: delete to 'end sound trigger' if not using sounds

//-- included to trap errors triggering sounds which delay the script firing
fTriggerSound(string sound, float volume)
//Written by Strife Onizuka
//-- tweaked by Void Singer
{
if (volume){
//-- makes sure sound is valid before playing
if ((key)sound);
else if (INVENTORY_SOUND == llGetInventoryType( sound ) );
else{
return;
}
llTriggerSound(sound, volume);
}
}
//-- end sound trigger

fTriggerSlide(){
//-- begin sound trip: delete to 'end sound trip' if not using sounds
if (Open)
{
fTriggerSound( CloseSound, CloseVol );
}else
{
fTriggerSound( OpenSound, OpenVol );
}
//-- end sound trip

llSetPos( llGetLocalPos() + Offset );
//-- reverse offset so next time it goes the opposite direction
Offset = -Offset;
//-- reverse open state tracking
Open = !Open;

//-- delete next line if not using autoclose
llSetTimerEvent( Timer * Open); //-- if closed timer is turned off
}

default
{
state_entry()
{
Offset = <EastWest, NorthSouth, UpDown>;
}

touch_start( integer vIntNull )
{
//-- safer to ignore simultaneaous touches in doors,
//-- so we dont bother processing more than the first
fTriggerSlide();
}

//-- removed on rez reset because it could reverse the open logic and break the offset.

//-- begin timer: delete to 'end timer' end if not using autoclose
timer()
{
//-- test if it's open so queued timer events don't accidently fire movement code
if (Open)
{
fTriggerSlide();
}
}
//-- end timer
}


edit:
if only using movement, no autoclose, no sounds all you need is
CODE

//Sliding Door v4
//Works when linked
//by Kayla Stonecutter
//-- tweaked heavily by Void Singer Mar 10, 2008

//How far in meters to travel in each direction. Two or all three can be used for angled movement
//NOTE: when linked, this is relative to the root prim
//Positive = move north, negative = move south
float NorthSouth = 0.5;
//Positive = move east, negative = move west
float EastWest = -0.0;
//Positive = move up, negative = move down
float UpDown = 0.0;

//misc variables
vector Offset;

default
{
state_entry()
{
Offset = <EastWest, NorthSouth, UpDown>;
}

touch_start( integer vIntNull )
{
llSetPos( llGetLocalPos() + Offset );
//-- reverse offset so next time it goes the opposite direction
Offset = -Offset;
}
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Zarni Torok
Registered User
Join date: 22 Feb 2007
Posts: 5
03-10-2008 18:12
Thank you very much for this Void, and its great how you set it out for me.
It really helps me understand these things more.


Edit
And works a treat as well :)