Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to make drawers in things that open?

Mailia Lioncourt
Registered User
Join date: 22 Jan 2005
Posts: 5
02-20-2005 11:25
How do i have the two pieces stay together without linking them so that the drawer will open and close?

Any help would be appreciated

Thanks
M
Sam Portocarrero
Jesus Of Suburbia
Join date: 23 May 2004
Posts: 316
02-20-2005 13:23
Humm wouldnt you link them, then place the "slide" or "open" script in the root prim?

Otherwise I dont know of an effect way, if you want an example IM me.

- Sam
_____________________
Mailia Lioncourt
Registered User
Join date: 22 Jan 2005
Posts: 5
02-20-2005 13:55
Ah okay, i know nothing of scripting so i'll see what i can find out, i'll message you in game if i get stuck again, thanks
Siobhan Taylor
Nemesis
Join date: 13 Aug 2003
Posts: 5,476
02-20-2005 14:09
It's not hard to make the drawer slide. What's hard is getting it to still work after you move the item.
_____________________
http://siobhantaylor.wordpress.com/
Mailia Lioncourt
Registered User
Join date: 22 Jan 2005
Posts: 5
02-20-2005 14:36
Yah so far thats the only part i'm having a problem wiht
Racer Plisskin
Rezerator
Join date: 2 Jan 2005
Posts: 147
02-23-2005 00:26
Here's a basic drawer script I just made and tested. It goes in the drawer prim.

This works properly only when the drawer is linked to the dresser. The drawer will slide in/out according to the +X direction of the base prim in the dresser.

It works if the drawer is 'free floating' as well but you would have to adjust the vector to move the drawer properly if it opens in any direction except 'North/Global +X"... ;)

NOTE: this example moves the drawer in and out by .5 meters. Adjust as needed.

CODE

integer is_open = FALSE; // assume the drawer starts out closed

default
{
state_entry()
{
}

touch_start(integer total_number)
{
if ( is_open )
{ // then close the drawer
llSetPos(<-0.5, 0.0, 0.0> + llGetLocalPos());
is_open = FALSE;
}
else
{ // open the drawer
llSetPos(<0.5, 0.0, 0.0> + llGetLocalPos());
is_open = TRUE;
}
}
}


If your drawer is more than 1 prim that needs to move, this could still work, but a bunch of interprim communication code would be needed to make the group of prims move together. Here is an example of how to do that:

/54/65/36377/1.html#post391653

Racer P.
Mailia Lioncourt
Registered User
Join date: 22 Jan 2005
Posts: 5
02-23-2005 14:24
thanks for scripting help i don't really get the second part about linking the peices
I have a drawer made of 3 prims at the bottom of a book case and i'm not quite sure what script i'm supposed to put where. I tried just using the one above and nothing happens and i don't know quite how to get the other one added to it or whatever i have to do, do i put two seperate scripts in the drawer peices? or just the base prim?? do i merge them into one?

sorry, i'm so lost with scripts i cant seem to make heads or tails of the infromation i downloaded from sl on it.
Racer Plisskin
Rezerator
Join date: 2 Jan 2005
Posts: 147
02-23-2005 15:58
OK.

There are 2 options.

If you don't mind having the drawer completely separate from the dresser (or bookcase or whatever) then link the 3 drawer prims together with the bottom/baseplate of the drawer as the root prim.

Put the simple script above in the root prim of the drawer. You can change llGetLocalPos to llGetPos if you want but you don't have to.

This will allow the drawer as a unit to open/close along the global X axis.

If you want to rotate the dresser, you will need to figure out the correct vector for the new drawer opening angle (not too hard with some trigonometry but still a pain in the but).

If you want to make your dresser all one big linked object, then you will need some interprim communication to allow for the 3 drawer parts to move in and out together.

The advantage of this is that you can rotate the dresser any way you want and the drawers will always open/close in the correct direction without having to update the scripts.

You will want to put something like this in all three drawer parts. Touching any of the three parts will trigger all the drawer parts to open/close.

For each drawer, you need to change the drawer_num to a different number.
EG: it should be set to 1 for all three pieces of the 1st drawer, 2 for all pieces of the 2nd drawer, etc...

Put a copy of this script into each of the drawer prims.

Link the 3 drawer prims in with all the other bookcase prims making sure the base prim of the bookcase is selected last. Unless you have other special prims in the bookcase that require a certain link order, only the base prim matters as to what order it's linked in as this determines what the +X axis of the entire object is.

--EDIT--
OK. I was able to login and debug this and make a few improvements.

Just drop this into each of the 3 drawer pieces and they will move together (adjust the movement from the 0.5 meter as needed for your application first though. ;) ).

--EDIT 2--
I realized I had bad logic that would cause issues if the object containing the drawers was moved/rotated after initial setup... It's fixed now.

CODE

integer drawer_num = 1; // this is the top drawer - all componenets
// of a drawer should use the same number.
// EG: change to 2 for all 2nd drawer prims
float slide_dist = 0.5; // distance in meters drawer should open
integer is_open = FALSE; // assume drawer starts out closed
string close_message = "CLOSE DRAWER"; // Close message to send to other prims
string open_message = "OPEN DRAWER"; // Open message to send to other prims

default
{

state_entry()
{
} // end of state_entry state

touch_start(integer nullvar)
{
if ( is_open )
{ // it's open, so close it
is_open = FALSE;
llMessageLinked(LINK_ALL_OTHERS, drawer_num, close_message, NULL_KEY);
llSetPos(<-slide_dist, 0.0, 0.0> + llGetLocalPos());
}
else
{ // it's closed so open it
is_open = TRUE;
llMessageLinked(LINK_ALL_OTHERS, drawer_num, open_message, NULL_KEY);
llSetPos(<slide_dist, 0.0, 0.0> + llGetLocalPos());
}
} // end of touch_start state

link_message(integer sender_num, integer num, string str, key id)
{
if ( num == drawer_num )
{
if ( str == open_message )
{ // we are bing asked to open
if ( ! is_open )
{ // if closed, then open. Otherwise do nothing
llSetPos(<slide_dist, 0.0, 0.0> + llGetLocalPos());
is_open = TRUE;
}
}

if ( str == close_message )
{ // we are bing asked to close
if ( is_open )
{ // if open then close. Otherwise do nothing
llSetPos(<-slide_dist, 0.0, 0.0> + llGetLocalPos());
is_open = FALSE;
}
}
}
} // end of link_message state
}


Racer P
Mailia Lioncourt
Registered User
Join date: 22 Jan 2005
Posts: 5
02-23-2005 17:24
thanks, i'll give it the old college try and let you know how it works out =D
Tamara Whiteberry
Registered User
Join date: 9 Jan 2008
Posts: 0
Keeping moving objects together
05-26-2008 14:57
After a day of hair tearing, a friend sent me the link to this thread and suddenly a light came on at the end of the tunnel!

However . . . I am building a cabinet with two opening drawers and two opening doors. The doors are fine. When I link the drawers to the rest of the cabinet they don't work. I want to link them so that others who might like my cabinet don't have to work with three separate objects and have to position the drawers themselves.

The code that is shown here almost works! Each drawer is made up of two prims, a hollow cube for the sides and a flattened cube for the base. I put the identical script into the two parts of the drawer, but they don't talk to each other and only the touched prim moves. The link message part is not working.

Help! What am I missing?