Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need some script help :)

Nyx Divine
never say never!
Join date: 11 Dec 2004
Posts: 1,052
11-27-2006 07:09
I have made a chest of drawers and each drawer has a script in it to open the drawer when touched.

I know how to change the script so that the drawers open correctly if I decided to change the rotation of my chest.

But what if I wanted to sell this chest of drawers? How can I sell it when the script will only work correctly if the chest is facing a certain way?

I assume there must be a way to fix this so any buyer can place this chest wherever they like and still have correctly opening drawers?

Here is the script I am currently using.....



default
{
state_entry()
{
llGetLocalPos();
}

touch_start(integer total_number)

{
state off;
}
}

state off
{
state_entry()
{
llSetPos(llGetPos() + <-0.5, 0, 0
>;);
}
touch_start(integer total_number)
{
llSetPos(llGetLocalPos() + <0.5, 0, 0>;);


state default;
}
}
_____________________
Yes Virginia there is an FIC!

If someone shows you who they are.....believe them!

Don't be afraid to go out on a limb, because that's where the fruit is!
Raeyan Aldrich
Registered User
Join date: 14 Oct 2006
Posts: 44
11-27-2006 07:15
for starters:

CODE

default
{
state_entry()
{
llGetLocalPos();
}

touch_start(integer total_number)
{
state off;
}
}

state off
{
state_entry()
{
llSetPos(llGetPos() + <-0.5, 0, 0>);
}
touch_start(integer total_number)
{
llSetPos(llGetLocalPos() + <0.5, 0, 0>);
state default;
}
}
Raeyan Aldrich
Registered User
Join date: 14 Oct 2006
Posts: 44
11-27-2006 07:25
and now that it's legible :)

i removed the state_entry from the default state since it had no bearing on the script at all. i also changed the state_entry on the 'off' state to use llGetLocalPos() instead of llGetPos() this way you are actually modifying the proper position when you add/subtract the 0.5m

this script is currently moving the drawer along it's local x axis, so if instead of moving in/out of the chest it moves side to side or up and down, change the <-0.5,0,0> to <0,-0.5,0> or <0,0,-0.5> and obviously do the same to the other one below it :) one of them will move it in the direction you want it to go.

CODE

default
{
touch_start(integer total_number)
{
state off;
}
}

state off
{
state_entry()
{
llSetPos(llGetLocalPos() + <-0.5, 0, 0>);
}
touch_start(integer total_number)
{
llSetPos(llGetLocalPos() + <0.5, 0, 0>);
state default;
}
}
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
11-27-2006 08:08
This will work for any rotation, assuming that the child prim is at ZERO_ROTATION relative to the root prim. if not, you'll have to adjust the movement vectors.

CODE

default
{
touch_start(integer total_number)
{
state off;
}
}

state off
{
state_entry()
{
llSetPos(llGetLocalPos() + <-0.5, 0, 0>*llGetLocalRot());
}
touch_start(integer total_number)
{
llSetPos(llGetLocalPos() + <0.5, 0, 0>*llGetLocalRot());
state default;
}
}
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
12-01-2006 21:38
Nope. It is incorrect to rotate the offset vectors since llSetPos is intelligent enough to know whether it's performing a local or global translation.

Raeyan's code is correct.