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

Openlife Forums

 Openlife Grid Forums
Minimize
 
  Openlife Forums  Scripting  Openlife LSL Ex...  Sliding door script
Previous Previous
 
Next Next
New Post 5/2/2008 7:03 AM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Sliding door script 
Modified By Pratyeka Muromachi  on 5/2/2008 7:05:14 AM)

Here's my humble attempt to scripting a sliding door. I use this or variations of it in my japanese sliding doors.

//**** Sliding door script ****
//**** by Pratyeka Muromachi ****

//**** Permission is granted to use this script any way you like ****




vector dpos;

integer doorSte = 0;
default
{
    state_entry()
    {
        llOwnerSay("Sliding door script is active");
    }
 
    touch_start(integer total_number)
    {

        if (doorSte == 0)
        {

            dpos = llGetPos();

            dpos = dpos + <2,0,0>; //calculate door position + 2m in X
            llSetPos(dpos);         //moves the door to new position
           
            doorSte = 1;
        }
        else
        {
         
            dpos = llGetPos();
            dpos = dpos - <2,0,0>;//calculate door position - 2m in X
            llSetPos(dpos);         //moves the door to new position
           
            doorSte = 0;
        }
    }
}


Meditating Avatar Gone for a walk.
 
New Post 5/3/2008 8:12 PM
User is offline Charmaine Andersson
47 posts
Openlife Newbie


Re: Sliding door script 

Hooray, Prat!  This script works SO bootifully--I needed a working sliding door script for a barn in one of my standalones--I just changed the 2 in the formula to a 10 and my barn door moves over 10 meters!

Yeah, little things like that really excite me :-D LOL

Thanks SO much for posting such a great, working script :-)

Charm

 


Charm
 
New Post 5/3/2008 11:14 PM
User is offline Bodhi Moo
49 posts
www.Bodhi-Sajeev.de
Openlife Newbie


sliding door error resolved 
Modified By Bodhi Moo  on 5/4/2008 12:46:54 AM)

Hello,

 

Thanks for the script. But i get following error.:

 

[5:10]  Sliding door: Error compiling script:

You must define a default state. Compile failed. 

UPDATE

Strange ... ,now it works. I put it into another prim and there it works.  ;-)

 

Bodhi

 

 
New Post 5/4/2008 3:21 AM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Re: sliding door error resolved 

Thanks! I'm not very good at scripting, I get stressed easily when the computer doesn't do what I intend but what I told it to do. It's a really quick and dirty script that move a prim back and forth. One problem is that if the region is restarted, the script resets and the last position becomes the closed position. So if the door was left open, that position becomes the closed position.

Of course, one way to correct that would be a timer to close the door after so many seconds. but I need a sliding door that can stay open.

I need the script to store the original closed position and to retrieve this position when the script is reset.

I'll have to study scripting a bit more. I know it can be done.


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




Re: Sliding door script 

here is an improved sliding door script.

It automatically detects the doors dimensions and orientation. if you modify the door in size or orientation, it will still function normally.

The motion of the door is divided into two steps, so your sliding door can be left half opened.

start copy below.

//**** Auto-adjust Sliding door script ****
//**** by Pratyeka Muromachi ****
//**** detects the door size automatically and adjust movement ****
//**** detects orientation of the door ****
integer opened = 0;

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

    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;
       
            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;
            }
        }
    }
}


Meditating Avatar Gone for a walk.
 
New Post 5/4/2008 3:25 PM
User is offline Elsja Vacano
58 posts
Openlife Apprentice




Re: Sliding door script 

There is the same script modify to memories the state accros region restart

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


default
{
    state_entry()
    {
        llOwnerSay("Sliding door script is active");
        llSetObjectDesc("0");
    }

    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);

        }
    }
}

 
New Post 5/4/2008 6:43 PM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Re: Sliding door script 

that is brilliant! I knew there had to be a way to store the state of the door. Thanks a lot.


Meditating Avatar Gone for a walk.
 
New Post 5/5/2008 1:41 AM
User is offline Elsja Vacano
58 posts
Openlife Apprentice




Re: Sliding door script 

No problemo,

It it possible to store several variable with this way:

 

store:

llSetObjectDesc(llDumpList2String(myList,";;");

 

Get it

myList=llParseString2List(llGetObjectDesc(),[";;"],[]);

(I write the answer here without testing in world, some little change may be need)

 

What it is important to know.

Never use llList2CSVand the its reverse if the list contains vector or even string with , (coma)

The reason is, when the string is converted to a list, it cannot make difference between  , as field separator or as data.

That why I prefer use ;; as separator.

Second, this is the way to use a string to contains, you can use this method to send data to another scrit.

just change llSetObjectDesc by llSay.

 

However if llSetObjectDesc is use make sure that the result string is lesser than the maximum allow by field 128 bytes if I have a good memory.

Otherwize, you can rapidely go in trouble espessialy if several scripts use this method and break the limit.

 

 

 

 

 
New Post 5/5/2008 1:31 PM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Re: Sliding door script 

Had to remove the "llSetObjectDesc("0");" because upon region restart it set the description to 0. We want to keep the last state of the door so this line is not required.

//**** 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");
    }

    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 5/5/2008 1:52 PM
User is offline Elsja Vacano
58 posts
Openlife Apprentice




Re: Sliding door script 


Had to remove the "llSetObjectDesc("0");" because upon region restart it set the description to 0. We want to keep the last state of the door so this line is not required.

oops,

That is bad, I need to add it to make the script working.

If the description is not set, the first time (and all after) the line integer opened =(integer)llGetObjectDesc(); will not works.

OpenGrid LSL dislike to cast to integer bad value. It shout and error message and does not assigns 0 at the variable.

 

So, state_entry must be:

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

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

 
New Post 5/5/2008 2:37 PM
User is offline Pratyeka Muromachi
239 posts
Openlife Rising Star




Re: Sliding door script 

Lol! the fickleness of LSL...that's the one condition I did not test, an empty description.

I'm certainly learning a lot with just a simple sliding door script..  Thanks again Elsja.

 


Meditating Avatar Gone for a walk.
 
New Post 5/5/2008 5:55 PM
User is offline Danny
17 posts
Openlife Newbie


Re: Sliding door script 

Great stuff, first script I'v got working in OL and I greatly appreciate it as scripting baffles me, also nice when people are willing to share their hard work for nothing in return, might be the crucial differance between OL and SL

 
New Post 5/6/2008 4:03 AM
User is offline Elsja Vacano
58 posts
Openlife Apprentice




Re: Sliding door script 

 Pratyeka Muromachi wrote

Lol! the fickleness of LSL...that's the one condition I did not test, an empty description.

I'm certainly learning a lot with just a simple sliding door script..  Thanks again Elsja.

No problemo,

You help me too. I have some trouble my an LSL script. I never found why.

I convice that the state_entry execution on region restart is the cause.

Need to check at it when I got some time.

 

Regards

 
Previous Previous
 
Next Next
  Openlife Forums  Scripting  Openlife LSL Ex...  Sliding door script
Privacy Statement | Terms Of UseAll Rights Reserved 2007,2008 3DX - Openlifegrid.com