Jump to content

Overflow pool that comes out from under the skybox and closes with timer


fascicularia
 Share

You are about to reply to a thread that has been inactive for 379 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello everyone,

I thank in advance the charitable soul who will help me.
I specify that I have no knowledge in scripting and that it is rather a request for help for a final script providing some explanations in its mode of operation.

I know it's a bit of a newbie who comes to ask that we chew him the job but hey, as much to recognize my incompetence in the matter.


Enough talking, I'll explain the problem to you.

I have an infinity pool whose sliding I activate thanks to this script:


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 = -15.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
}
 

Everything works wonderfully, the whole structure responds well to the script.

I would like to include two things:
1/ be able to bring the structure out from under the skybox and reposition it at the right height afterwards

2/ remove the closing by touch from the pool and replace it with a timer programmed for 1 or 2 hours.

Thank you again in advance for the charitable soul who will take pity on the poor script newbie that I am

Link to comment
Share on other sites

20 hours ago, fascicularia said:

be able to bring the structure out from under the skybox and reposition it at the right height afterwards

The positioning in your script as currently written is being done by the llSetPos functions. In both instances, the position is being set to a vector which is the combination of two other vectors: <slide_dist, 0.0, 0.0> and llGetLocalPos(). The first vector uses the variable slide_dist (which is defined to have a value of -15.5) for the x component, and keeps the y and z portions the same as 0.0. The second vector is the result of calling llGetLocalPos which returns the value of the prims local position relative to the root (or the root's global position if the script is in the root prim). So in essence, the script is only moving along the X axis by -15.5 meters. Depending on whether you're opening or closing the thing, the value of slide_dist is negated. So it will either move backwards along the x axis by 15.5 meters, or forward along the x axis by 15.5 meters.

If you want to also change the vertical position, you would could similarly modify the z component of the first vector. Following the format of your script, define another float variable... something like vertical_dist and set it equal to whatever value you want it to move by from its closed position. Remember, if the value is positive, the object would move "up", and if negative, it'll move "down". Take this into consideration when using it, as you will need to carefully negate the value on the toggle. Replace the second "0.0" in the first constructed vector with this variable to make use of it. As an example:

llSetPos(<slide_dist, 0.0, vertical_dist> + llGetLocalPos());

 

21 hours ago, fascicularia said:

remove the closing by touch from the pool and replace it with a timer programmed for 1 or 2 hours

At present, the device opens and closes on touch. When someone touches the object, the script within will run the code within the touch_start event. As an aside, the comments in your script erroneously call them "states" when in fact they are "events". A state is something else entirely. The touch_start code does one thing: it checks the value of the is_open variable. If the variable is equal to TRUE, then it assumes the pool is already opened, so it runs the code go close it, and most importantly, it updates the value of is_open to now be FALSE, signifying the pool is closed. On the other hand, if the value of is_open was FALSE, the script assumes the pool was currently closed and instead runs the code to open it - also updating the is_open variable to be TRUE, and thus reflecting the open or closed state of the pool. This is how the toggle works and allows for two different actions to happen from the same initial touch.

If you want to make the pool close itself after a set amount of time, you would want to employ a timer. The basic example would be to call llSetTimerEvent with the desired duration (in seconds) when you open the pool. After that time has elapsed, the script will automatically run the timer event. It is in this event that you would have similar code to close the pool: which would be setting is_open to FALSE, and calling llSetPos like you did in the touch_start event. You would also want to stop the timer so it doesn't repeat after another hour - because timers will repeat forever until stopped. Running timers are stopped by calling llSetTimerEvent(0.0).

I would recommend you keep the open/close on touch toggle so that you may close the pool early if desired. Adding the timer to auto-close it would not require you to remove the touch-close aspect. Though I would also add a line to stop the timer on the touch-close part as an extra precaution.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 379 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...