Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Wonky Open-Door Script

Solanghe Sarlo
Gypsy Free Thinker
Join date: 19 Jul 2006
Posts: 644
10-05-2007 12:34
I have a basic door open script that works fine in a traditional vertical opening door. However, when I put this same script into a lid on a horizontal box, it goes all wonky and will not maintain the integrity of the movement. It will open properly once, then it will cause the lid to slide or twist off center.

I guess the script needs a tweak, but I do not know which command line or what values to put in. Help!

Thanks,

Sol
_____________________
The key to a contented life: Figure out who you are, what you are, fix what you can and make peace with the rest.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-05-2007 18:22
post it

whenever a door script closes it usually standard practice to reorient it to its default, its probably just hard coded somewhere
Solanghe Sarlo
Gypsy Free Thinker
Join date: 19 Jul 2006
Posts: 644
10-05-2007 19:09
From: Osgeld Barmy
post it

whenever a door script closes it usually standard practice to reorient it to its default, its probably just hard coded somewhere



Sorry Os, I don't know what you mean here. Can you tell me what you mean without using jargon? I'm not a scripter. Plain language please. :o
_____________________
The key to a contented life: Figure out who you are, what you are, fix what you can and make peace with the rest.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-05-2007 19:43
From: Solanghe Sarlo
Sorry Os, I don't know what you mean here. Can you tell me what you mean without using jargon? I'm not a scripter. Plain language please. :o

It would be easier showing you in the script, which was what Osgeld was asking for. Post it and we will get it up and running for you.
_____________________
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
Solanghe Sarlo
Gypsy Free Thinker
Join date: 19 Jul 2006
Posts: 644
oh, here is the script....
10-06-2007 20:19
Oh, OK! Thanks for your help! Here is the script:


// COPYRIGHT (C) LEE LUDD 2005
// FREE SWINGING DOOR
// User is permitted to make copies for his or her own use, to modify the code,
// and to give (but not to sell) copies to others.

float rot;
float dist;
float rot_used;
integer door_move_steps = 3;
integer door_direction = 1;
integer touch_flag;
integer lock_flag;
//float rot=llSine(PI / 4.0);


door_move(integer door_swing_direction)
{
integer step;

float door_swing_angle = door_swing_direction * PI_BY_TWO;

vector delta_euler = <0.0, door_swing_angle / door_move_steps, 0.0>;
rotation delta_rot = llEuler2Rot(delta_euler);
rotation next_rot = llGetRot();

for (step=0; step<door_move_steps; step++)
{
next_rot = delta_rot * next_rot;
llSetRot(next_rot);
}
}


default
{
state_entry()
{
state closed;
}
}

state closed
{
touch_start(integer num)
{
door_move(door_direction);
state open;
}

on_rez(integer num)
{
llResetScript();
}
}

state open
{
touch_start(integer num)
{
door_move(-door_direction);
state closed;
}

}
_____________________
The key to a contented life: Figure out who you are, what you are, fix what you can and make peace with the rest.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-06-2007 21:40
Here are the two places you edit:

This one says which way it will swing:
integer door_direction = 1;

to swing in the opposite direction change it to:
integer door_direction = -1;


This one determines which axis it will pivot on. It is set now to pivot on the Y axis:
vector delta_euler = <0.0, door_swing_angle / door_move_steps, 0.0>;

So to pivot on the X axis you would change it to:
vector delta_euler = <0.0, 0.0, door_swing_angle / door_move_steps>;

and for the X axis:
vector delta_euler = <door_swing_angle / door_move_steps, 0.0, 0.0>;

Once you have it opening and closing like you want then you can rotate it to the correct orientation for the chest and it will still work correctly.
_____________________
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
Solanghe Sarlo
Gypsy Free Thinker
Join date: 19 Jul 2006
Posts: 644
10-07-2007 11:26
Thank you Jesse! I will let you know how it works out. I appreciate your help very much. :D
_____________________
The key to a contented life: Figure out who you are, what you are, fix what you can and make peace with the rest.
Solanghe Sarlo
Gypsy Free Thinker
Join date: 19 Jul 2006
Posts: 644
10-14-2007 16:50
Hi Jesse,

Your advice helped and the door is swinging appropriately now, thank you! Now, can you tell me how to link the lid and the bottom box so that when the lid is touched the whole box doesn't move, only the lid?

:o

Sorry, I'm not scripty. Thanks again.
_____________________
The key to a contented life: Figure out who you are, what you are, fix what you can and make peace with the rest.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-14-2007 17:14
From: Solanghe Sarlo
Hi Jesse,

Your advice helped and the door is swinging appropriately now, thank you! Now, can you tell me how to link the lid and the bottom box so that when the lid is touched the whole box doesn't move, only the lid?

:o

Sorry, I'm not scripty. Thanks again.

When you link them, be sure to select the lid 1st and then the box and hit ctrl L. So let's start over. Right click/edit the link set and hit ctrl/shift/L, this will unlink them. Then right click/edit the lid and while holding down the shift key, select the box. Now hit ctrl L to link them. You want the lid to be the child prim and if you have it done right, when you right click/edit the set, the lid will be outlined in blue and the box will be outlined in yellow.

And yes, you are officially a scripter now.
_____________________
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
Solanghe Sarlo
Gypsy Free Thinker
Join date: 19 Jul 2006
Posts: 644
11-01-2007 12:47
Hi Jesse,

Just wanted to say thankyou, script works fine now! I appreciate your help = )
_____________________
The key to a contented life: Figure out who you are, what you are, fix what you can and make peace with the rest.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-01-2007 13:21
From: Solanghe Sarlo
Hi Jesse,

Just wanted to say thankyou, script works fine now! I appreciate your help = )

COOOOL!!!!!!!!!!!!!!!!!
And you got to learn something too!
Keep coming back and we will turn you into a full fledged scripter in no time :)
_____________________
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
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-01-2007 14:27
not to eclipse Jesse ('cause I like her style) but here's a dif door script... (that hasn't made it through the library page yet so copied here)

CODE


//--// v7-D Feebie Type 1 Door Script //--//
//--// Works At ANY Angle //--//

//-- works in ANY single prim door, linked or un-linked
//-- works in muti prim doors NOT linked to a larger structure
//-- REQUIREMENTS: a cut root prim, suggest cube, pathcut start=.125, end=.625
//-- CAVEAT: single prim doors are limited to 5m width

//--// USERS MODIFY HERE v
integer vgVecDoorSwing = 90;
//-- use -# to reverse the direction of swing, eg. -90;


rotation vgRotDoorSwing;

default{
state_entry(){
vgRotDoorSwing = llEuler2Rot( <.0, .0, (float)vgVecDoorSwing * DEG_TO_RAD> );
}

touch_start( integer vIntTouches ){
//- small hack to reverse direction of swing on each
//- touch & avoid lsl funkiness regarding rotation division
vgRotDoorSwing.s *= -1;

llSetLocalRot( vgRotDoorSwing * llGetLocalRot() );
}
}

//-- IF Redistributing as-is:
//-- Please leave script full permissions & include all comments


to use in lids, create lid as door, move/rotate (via object edit) into place, done.

to create realistic hinge action:
-in object edit:
create sphere,
dimple end = .5
change to box
path-cut start = .125, end = .625
rotation(degrees) x = 90, y = 0, z = 0

-in the script, change
vgRotDoorSwing = llEuler2Rot( <.0, .0, (float)vgVecDoorSwing * DEG_TO_RAD> );
to
vgRotDoorSwing = llEuler2Rot( <.0, (float)vgVecDoorSwing * DEG_TO_RAD, .0> );

Done.
_____________________
|
| . "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...
| -
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-01-2007 17:16
From: Void Singer
not to eclipse Jesse ('cause I like her style) but here's a dif door script...


Hey I am a fan of yours too:)
I was trying to remember just how many times we are peppered with questions concerning door scripts and I quicky lost count. Your script is by far the most basic and easiest I have seen. So then logically I was thinking of how to make it so that even the newest of the noobs could use it and came up with this:
CODE

//Inspired by Void Singer's brilliantly simple door script
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
////////////THESE ARE THE VARIABLES YOU CAN CHANGE/////////
//////////Set x,y or z to TRUE to swing on that axis///////
integer x = FALSE;
integer y = FALSE;
integer z = TRUE;
integer reverse_swing = FALSE;//Change to TRUE to
//////////////////////////////reverse the direction
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
////////////DO NOT CHANGE BELOW HERE///////////////////////
integer Door_Rot = 90;
rotation Door_Swing;
vector Door_Axis = <0.0,0.0,0.0>;

default
{
state_entry()
{
if(reverse_swing == TRUE)
{
Door_Rot *= -1;
}
if(x == TRUE)
{
Door_Axis.x = (float)Door_Rot * DEG_TO_RAD;
}
if(y == TRUE)
{
Door_Axis.y = (float)Door_Rot * DEG_TO_RAD;
}
if(z == TRUE)
{
Door_Axis.z = (float)Door_Rot * DEG_TO_RAD;
}
Door_Swing = llEuler2Rot(Door_Axis);
}

touch_start(integer vIntTouches)
{
Door_Swing.s *= -1;
llSetLocalRot( Door_Swing * llGetLocalRot());
}
}

Would love comments and examples of the easiest, most user freindly door script. How close can we come to a FOOL-proof script?
_____________________
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
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-02-2007 09:15
heh GMTA, the previous version of my door script looked alot like that... I decided against it because a not everyone gets vectors (it looked ~like this)
CODE

//-- instruction to change swing, blah blah
vector vgVecSwing = <.0, .0, 90.0>;
integer vgBooClockWise= TRUE;
rotation vgRotSwing;

//-- and then in the default entry
if (!vgBooClockWise){
vgVecSwing *= -1;
}
vgRotSwing = llEuler2Rot( vgVecSwing * DEG_TO_RAD );

(actually I was using 3 states before default[calculations & choose start state], clock, anti clock, and doing the rotation in the state exit of each of these so it didn't auto rotate on compile/reset)

the reasons I ditched it are
1) a single number to edit (vs 1 or 2 vectors, see below)
2) direction is is controlled in the same number (saves memory, impler)
3) doors are simple to understand, and since it works at any angle, a "door" is all you need (lids, hatches, etc)
4) hinge side can be reversed by turning the door in object edit (see below even more complex example) and door swing reversed to create double doors (no need for other options on simple hing action)
5) less code, easier to read, smaller memory footprint
6) more advanced users can easily mod to their needs

I used to have this in a position moving door (before I combinded the rotation and hinge side)
CODE

//-- only use '-1', '0', or '1' for the following line
vector vgVecHingeSide = <1, 0, 0>; //-- instructions
vector vgVecDoorSwing = <0, 0, 90>; //-- instructions
integer vgBooClockwise = TRUE;

vector vgVecDoorSizeOffset;
rotation vgRotSwing;

state_entry(){
vgVecDoorSizeOffset= llGetScale() / 2; //to get half the dimensions
vgVecDoorSizeOffset.x *= (vgVecDoorSwing.z != 0) * vgVecHingeSide.x;
vgVecDoorSizeOffset.y *= (vgVecDoorSwing.x != 0) * vgVecHingeSide.y;
vgVecDoorSizeOffset.z *= (vgVecDoorSwing.y != 0) * vgVecHingeSide.z;
vgRotSwing = llEuler2Rot( vgVecDoorSwing * DEG_TO_RAD );
}

//--the offset is needed for position doors because we rotate around the side, instead of cutting so we need to know where the side is
_____________________
|
| . "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...
| -
Max Pitre
Registered User
Join date: 19 Jul 2006
Posts: 370
11-02-2007 15:45
From: Void Singer
not to eclipse Jesse ('cause I like her style) but here's a dif door script... (that hasn't made it through the library page yet so copied here)


//--// USERS MODIFY HERE v
integer vgVecDoorSwing = 90;
//-- use -# to reverse the direction of swing, eg. -90;




Could this be made so the description block of the object be used to change the direction instead of modifying the script?
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-02-2007 15:58
From: Max Pitre
Could this be made so the description block of the object be used to change the direction instead of modifying the script?

Yep you would just have to do an if text on llGetObjectDesc and if such and such then multiply vgVecDoorSwing * -1
_____________________
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
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-02-2007 16:04
From: Void Singer
heh GMTA, the previous version of my door script looked alot like that...

OMG I feel soooooo old sometimes. I couldn't figure out what GMTA meant, I knew LOL, LMAO etc but not that one. So I googled it and couldn't figure out what the heck the Georgia Motor Trucking Association had to do with scripting. :eek:
So now I am sitting here LMAO because I finally saw what it meant a few returns down in the search.

Maybe I'l wait till everyone is asleep tonight and go run out in the backyard naked and then back in again to regain my young at heartness!!!!!!!!!!!!!!!
_____________________
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
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-02-2007 17:38
you could also, in the default state entry call
vgVecDoorSwing = (integer)llGetObjectDesc();
and place a number in the description, and even close the script....

but my hope is that people will use this which is why it has a note on the bottom requesting it be open mod if used as is

EDIT: you can actually tell some of what I changed in this script from previous versions....
vgVecDoorSwing SHOULD actually be vgIntDoorSwing throughout....

@Jesse
you can't be that old, I've heard GMTA for the last ten years online... guess we just travel in different circles =)
_____________________
|
| . "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...
| -
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
11-02-2007 20:05
Once you have the door positioned correctly to its closed position, use the Tools "reset scripts in selection" menu command and see if that doesnt fix it. I have a sliding door script that has to be reset that way whenever it is repositioned, otherwise it reverts back to its previous location within the sim, which can be far away from where you are trying to place it.
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo