Tuesday, December 02, 2008
USERLOGIN PASSWORD Remember?
You are here » Learning Center ยป Forums

Openlife Forums

 Openlife Grid Forums
Minimize
 
  Openlife Forums  Scripting  LSL Help  Saving position across sim restarts
Previous Previous
 
Next Next
New Post 6/21/2008 6:16 PM
Online now... Capt Macca
136 posts
Openlife Handyman




Saving position across sim restarts 

If this sliding window is left open, it will open again the next day. How can it remember that it was open? Same for doors. Is the only answer, auto-close?

//---/---/---/------------------------------------------//_______________________>>
vector      DIST    = <0,0,0.3>; //set movement amount and direction
float       SLEEP       = 0.3;      //set time between movements
float       VOLUME      = 0.8;      // sound volume, 1.0 loudest, 0.0 to disable sound
key         SOUND_OPEN  = "378b553c-d511-aab3-d220-c239a6d15ad3";
key         SOUND_CLOSE = "8ae0e71f-6763-067f-073b-b299d687bc98";
vector      oPos;
vector      cPos;
//---/---/---/------------------------------------------//_______________________>>
open()
{
         llTriggerSound(SOUND_OPEN, VOLUME);
         cPos = llGetPos();
         llSetPos(llGetLocalPos() + DIST);
         llSleep(SLEEP);
         llSetPos(llGetLocalPos() + DIST);
         llSleep(SLEEP);
         llSetPos(llGetLocalPos() + DIST);
}
close()
{
         llTriggerSound(SOUND_CLOSE, VOLUME);
         oPos = llGetPos();
         llSetPos(llGetLocalPos() - DIST);
         llSleep(SLEEP);
         llSetPos(llGetLocalPos() - DIST);
         llSleep(SLEEP);
         llSetPos(llGetLocalPos() - DIST);
}
//---/---/---/------------------------------------------//_______________________>>
default
{
    state_entry()
    {
         cPos = llGetPos();  // remember where we're supposed to be closed
         state closed;
    }  
    on_rez(integer start_param)
    {
        llResetScript();
    }
    changed(integer change)
    {
        if(change & CHANGED_OWNER)
        llResetScript();
    }
}

state closed
{
    state_entry()
    {
        cPos = llGetPos();
    }
   
    touch_start(integer total_number)
    {
        if ((llDetectedKey(0) == llGetOwner()) || llDetectedGroup(0))
        {
            open();
            state opened;
        }
        else
        {
            llWhisper(0,"Not allowed.");
        }
    }
    link_message(integer sender, integer num, string message, key id)
    {
        if(message == "Open1")
        {
            open();
            state opened;
        }
    }
}
state opened
{
    state_entry()
    {
        oPos = llGetPos();
    }
   
    touch_start(integer total_number)
    {
//---/---/---/------------------------------------------//_______________________>>
        if(llDetectedKey(0) == llGetOwner() || llDetectedGroup(0))
        {
            close();
            state closed;
        }
        else
        {
            llWhisper(0,"Not allowed");
        }
    }
    link_message(integer sender, integer num, string message, key id)
    {
        if(message == "Close1")
        {
            close();
            state closed;
        }
    }
//---/---/---/------------------------------------------//_______________________>>       
}


Captain of my realm... Rox (Goes off to make a new cap) Happy Gridding...
 
New Post 6/21/2008 7:56 PM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Re: Saving position across sim restarts 

Check this thread, it is a sliding door with 4 positions and it remembers where it was across region restart. Works beautifully. here is the script in it's final form:

 

//**** Auto-adjust Sliding door script ****
//**** detects the door size automatically and adjust movement ****
//**** detects orientation of the door ****

//**** remembers the door's last position through a region restart or script reset




default
{
   

state_entry()
    {
        llOwnerSay("Sliding door script is active");

       if(llGetObjectDesc()=="") llSetObjectDesc("0"); // if any, initialize Object's Description as storage variable
}



    touch_start(integer total_number)
    {

        {         
            vector mySize = llGetScale();
            vector myPos  = llGetPos();
            rotation myRot = llGetRot();
            vector unitForward = llRot2Fwd(myRot);
            vector unitHorizontal = llRot2Left(myRot);
            vector unitVertical = llRot2Up(myRot);
     
            float myWidth = mySize.x;
     
            integer opened =(integer)llGetObjectDesc();
          
            if (opened == 0)
            {
                vector targetPos = myPos - ((myWidth/2.1)*unitForward);
                llSetPos(targetPos);         
            }
     
     
            if (opened == 1)
            {
                vector targetPos = myPos - ((myWidth/2.1)*unitForward);
                llSetPos(targetPos);         
            }
     
 
            if (opened == 2)
            {
                vector targetPos = myPos + ((myWidth/2.1)*unitForward);
                llSetPos(targetPos);         
            }
     
     
            if (opened == 3)
            {
                vector targetPos = myPos + ((myWidth/2.1)*unitForward);
                llSetPos(targetPos);          
            }

            opened = opened + 1;
            if (opened == 4)
            {
                opened = 0;
            }
            llSetObjectDesc((string)opened);

        }
    }
}


Meditating Avatar Gone for a walk.
 
New Post 6/22/2008 6:44 AM
Online now... Capt Macca
136 posts
Openlife Handyman




Re: Saving position across sim restarts 

 I put that script into a linked prim (window) and when I clicked it the whole build dissapeared. Later, on the mini map, I saw a blue dot in the void outside the sim next door. It was the prim I put the script in. I took a copy and deleted the prim, went back and tried to rez the copied prim a couple of times... Nothing.

Came back 2 hours later.. 3 blue dots, same place, out in void of sim next door. Turns out the previous rez attempt  worked but placed the build 100 meters above me and the single prim out in the void, 3 times.

I created 5 prims, linked them and put the script into a child prim. Same thing happened.

Dunno if Im clear enough about what happened but I wouldnt link anything with that script in it.

Do you know why it goes wild?


Captain of my realm... Rox (Goes off to make a new cap) Happy Gridding...
 
New Post 6/22/2008 8:23 AM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Re: Saving position across sim restarts 

you must use this script in an "unlinked prim".

I don't know of any script that moves a linked prim relative to the rest of the linked set.


Meditating Avatar Gone for a walk.
 
New Post 6/22/2008 8:40 AM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Re: Saving position across sim restarts 

I have tweaked the script to work with your windows in your tin shed at the sandbox island. I'll leave one set of said windows by your shed there. free to copy of course.


Meditating Avatar Gone for a walk.
 
Previous Previous
 
Next Next
  Openlife Forums  Scripting  LSL Help  Saving position across sim restarts
Privacy Statement | Terms Of UseAll Rights Reserved 2007,2008 3DX - Openlifegrid.com