Don't click here unless you want to be banned.

LSL Wiki : EyanaYohkoh

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org
Eyana Yohkoh, LSL dabbler.

It is a FACT that Feli is cuter than Eya!

Page slowly under construction.

Eyana Yohkoh's script examples:

Double Tap Detection

Basic Opacity Change: Method 1
// Change Opacity Script
// This script will change the transparency when the prim is touched.
// The first click will make it 50%, the second will make it invisible
// and the third will set it back to normal.



default
{
    state_entry()
    {
        llSetAlpha(1.0, ALL_SIDES);     // this will make the prim completely solid
                                        // the 1.0 is the alpha, and alpha goes from
                                        // 0.0 to 1.0 with 0.0 being invisible.
                                        // ALL_SIDES can be replaced with a number if
                                        // you want just one side of the prim to hide.
    }

    touch_start(integer num_detected)   // this says everything in the following brackets
                                        // will happen whenever the prim is touched.
    {
        state seethrough;               // this will make the script jump down to the next
                                        // state. a state is basically a set of commands
                                        // that becomes active only when you tell the script
                                        // to go to that new state.
    }
}


state seethrough                        // this is the new state to set it to 50% alpha.
{                                       // the script doesn't go here unless it has a specific
                                        // instruction to do so.
    state_entry()           // every time you go into a new state you can have a state entry
                            // where stuff happens as soon as it enters that state
    {
        llSetAlpha(0.5, ALL_SIDES);     // this sets the prim to 50% see through.
    }
    
    touch_start(integer total_number)
    {
        state invisible;            // when touched the script will go to a third state
    }
}

state invisible                         // this state is for everything that happens to make it
                                        // invisible as well as a touch thingie to make it go
                                        // back to the beginning of the script
{
    state_entry()
    {
        llSetAlpha(0.0, ALL_SIDES);     // sets the prim to invisible as soon as this
                                        // state starts.
    }
    
    touch_start(integer total_number)
    {
        state default;                  // when touched this will send the script to the
                                        // beginning.
    }
}

Basic Opacity Change: Method 2
// Change Opacity method 2
// This is an alternate way to cycle through opacity levels by using only one state.

float alpha;    // this is created outside of the state so the script will
                // know that this float thing will be used throughout the
                // whole thing so now in the script you can just use "alpha"
                // instead of "float alpha" to change it's value.
                // a float is a number that has decimal places
                

default
{ // beginning of state
    state_entry()
    {   // stuff between this set of brackets happens when you first load the script
        // or the script gets reset

        alpha = 1.0;              
                                        // the alpha part on llSetAlpha needs a float
                                        // number between 0.0 and 1.0

        llSetAlpha(alpha, ALL_SIDES);   // this will set the prim to be completely
                                        // visible when the script loads.
    }

    touch_start(integer total_number)
    {
        if ( alpha == 1.0 )             // this starts an if statement. basically this is
                                        // checking to see if the number set for alpha is
                                        // equal to 1.0. I honestly don't know why it
                                        // needs double equals signs, but it does. ^^
        {   // bracket to start doing stuff if the alpha is 1.0

            alpha = 0.5;    // changing the value of the alpha to 0.5 so next time
                            // it's clicked it can check the number again properly
            
            llSetAlpha(alpha, ALL_SIDES);   // goes to 50% transparency now
        }   // bracket to end the first if statement
        
        else if ( alpha == 0.5 )        // "else if" is what you use for the script to keep
                                        // checking stuff in case that first if statement
                                        // isn't valid
        {   // bracket starts the else if stuff
            alpha = 0.0;                // sets the alpha to zero, which will make it invisible
            llSetAlpha(alpha, ALL_SIDES);
        }  // end this else if stuff
        
        else if ( alpha == 0.0 )        // if the alpha is zero we want to make it go
                                        // back to regular without any transparency
        {
            alpha = 1.0;        // changing the alpha number to make it solid
            llSetAlpha(alpha, ALL_SIDES);
        }
    } // end of touch stuff
} // end of state

Timer Example #1
// this script is to show an example of how llSetTimerEvent and the timer() event work

default
{
    touch_start(integer touchnumber)        // for this example we will start the timer
                                            // countdown after the scripted prim is touched
    {
        llSetTimerEvent(10);                // this tells the script to wait 10 seconds and
                                            // then trigger a timer() event.
    }
    
    timer()                                 // this is the start of the timer event. a timer
                                            // event includes everything you want the script
                                            // to do after it has waited the amount of time
                                            // set by a llSetTimerEvent
    {
        llSay(0, "Raar! It's been ten seconds!");
    }                                      
        
}

Timer Example #2
// this script will demonstrate how to use llSetTimerEvent and timer() event
// in a repeatable fashion.

// after touching the prim, this script will make the object say something every
// ten seconds over and over and over and over instead of just once after touching
// like in the Timer Example #1 script.

default
{
    touch_start(integer touchnumber)
                                    
    {
        llSetTimerEvent(10);                // this will make the script start counting to ten
                                            // when it reaches ten it will go to the timer event
    }
    
    timer()             // again, everything in the timer() event will occur whenever
                        // the script has a timer event countdown trigger.
    {
        llSay(0, "Raar! It's been ten seconds!");       // this makes the object say something
        llSetTimerEvent(10);                // setting a new timer countdown within the timer
                                            // event basically means that whenever the timer
                                            // event goes off the first time and every time
                                            // thereafter it will start counting to ten again,
                                            // raar, and then count to ten again, and raar, etc.
    }                                      
        
}

// basically what happens with this is:
// click, count to ten, "Raar!", count to ten again, "Raar!", count to ten again, "Raar!"
// until inifinity.

Timer Example #3
// it's time to take the timer event a little further to show an example of what
// sort of flexibility you can use with timers.

// this example script will make the object Raar three times after ten seconds
// and instead of Raaring a fourth time, it will play a sound and stop repeating
// the llSetTimerEvent.

integer RaarTimes = 0;          // this is an integer to keep track of how many
                                // times the timer has gone off. it will be used
                                // in the timer() event to check whether to Raar
                                // or play the sound and stop counting.

default
{
    touch_start(integer touchnumber)
    {
        llSetTimerEvent(10);            // this sets the timer to count to ten seconds
        RaarTimes = 0;                  // we want to make sure the integer is set to zero
                                        // after touching in case someone is clicking this
                                        // again after it's already been clicked and the number
                                        // has been added to.
    }
    
    timer()
    {
        if ( RaarTimes < 3 )        // if RaarTimes is less than three then we want it to
                                    // do two things: Raar and start the timer counting again
                                    // but it also needs to add 1 to the RaarTimes integer
                                    // since it is counting how many times it's said something.
        {
            llSay(0, "Raar!");      // Raar!
            llSetTimerEvent(10);    // setting the timer again
            RaarTimes = RaarTimes + 1;      // this adds one to the RaarTimes integer
        }
        
        else                    // else will happen if the above if statement(s) are not true
                                // so this will happen whenever RaarTimes is not less than three.
        {
            llPlaySound("8c988d2d-c8c0-8aa2-f697-d266ad933ff8", 1.0);
                                // ^ this will play the sound at full volume. if you want
                                // the be at half volume you can change the number 1.0 to
                                // 0.5 or any other volume would be a number anywhere between
                                // 0.0 and 1.0.
            llSetTimerEvent(0.0);       // this will clear all timers that might be counting
                                        // so the only way to have the timer event to start
                                        // over again would be if someone clicked the prim again.
                                        // a SetTimerEvent of zero means there are no timers at
                                        // all anymore being kept track by the script.
        }
        
    }
}

Timer Example #4
// this script will start an endless cycle of opacity changes whenever touched, but it
// can be turned off with a second touch.
// this combines some of the ideas used in the Change Opacity example scripts
// with the timer examples.

// this will cycle through four levels of opacity: 100%, 75%, 50%, and 25%
// the float numbers used for each of these levels: 1.0, .75, .5,      .25



integer on = FALSE;     // this will be used to check whether or not the cycling is
                        // turned off or on
                        // integers can be whole numbers or can be TRUE or FALSE.
                        // basically TRUE is looked at by the script as being a number 1
                        // and FALSE is looked at as being the number zero.
                        
integer timerCount = 0;     // this will be used and changed in the timer event to keep
                            // track of which opacity level to use

default
{
    touch_start(integer touched)
    {
        if ( !on )      // this checks to see if on is not TRUE. the ! means it's looking for
                        // on to be FALSE
        {
            llSetTimerEvent(0.5);       // we want to change opacity every three seconds
            on = TRUE;                  // since on was FALSE, we now want to set it to
                                        // TRUE so the script knows that it is turned on
                                        // the next time it is clicked so it can turn it off        
        }
        else if ( on )                  // if the script is on ( on = TRUE ) then when it's touched
                                        // we want to turn it off and make sure everything is
                                        // set back to normal
        {
            // first we clear the timers so things stop happening:
            llSetTimerEvent(0.0);
            
            // then the object needs to be set back to full opacity:
            llSetAlpha(1.0, ALL_SIDES);
            
            // then reset timerCount to zero so the script can keep track of opacity
            // levels properly the next time it is turned on:
            timerCount = 0;
            
            // lastly the script needs to know that we've turned it off so the next time
            // it is clicked it will turn on again
            on = FALSE;
        }
    }   // end of touch stuff
    
    timer()         // this is all the stuff that will happen when the timer goes off
    {
        if ( timerCount == 0 )
        {
            llSetAlpha(0.75, ALL_SIDES);        // fade to 75% opacity the first time
            timerCount = timerCount + 1;        // adds one to the timerCount
            llSetTimerEvent(0.5);               // makes the timer start counting again
        }
        
        else if ( timerCount == 1 )          // if the timer has already been triggered once
                                            // we know the alpha was already set to 0.75
                                            // so this second time the timer is triggered
                                            // we will set the alpha to 50% (0.5)
        {
            llSetAlpha(0.5, ALL_SIDES);
            timerCount = timerCount + 1;    // add to timerCount so the next time the timer is
                                            // triggered it will know it's been done twice already
            llSetTimerEvent(0.5);           // set the timer event again or else nothing will happen
        }
        
        else if ( timerCount == 2 )      // if the timer has been done twice
        {
            llSetAlpha(0.25, ALL_SIDES);    // set the object to 25% opacity
            timerCount = timerCount + 1;    // this should end up equalling 3 so the next time
                                            // the timer event triggers the script will bypass all
                                            // the above if statements
            llSetTimerEvent(0.5);           // keep the timer counting again
        }
        
        else if ( timerCount == 3 )      // the timer has been done three times
                                        // so now we want it to set the opacity back to solid
                                        // and start the fading cycle again
        {
            llSetAlpha(1.0, ALL_SIDES);     // this sets the object back to fully solid
            
            // timerCount is now set back to zero so the next time the timer triggers
            // it will start using the above if statements again
            timerCount = 0;
            llSetTimerEvent(0.5);       // set the timer again so things keep happening
        }
    } // end of timer stuff
    
} // end of state

// end of script

// <3

Animation and Timer Example
default
{ // beginning of state

    attach(key id)
    
    {           // everything in this section will happen when the scripted item gets attached
        llSetTimerEvent(5.0);       // will trigger the timer event after five seconds.
                                    // SetTimerEvent is a one-time countdown to zero so
                                    // to have a timer repeat itself there needs to be
                                    // another llSetTimerEvent somewhere.
        llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
                                            // ^ gets permission to play an animation on the owner
        llStartAnimation("open mouth");     // starts playng the animation
    }
            
    
    
    timer()     // everything in this section will happen once after the amount of time
                // specified by llSetTimerEvent
    {
        llStartAnimation("open mouth");     // plays the animation again
        llSetTimerEvent(5.0);               // setting a timer here means that every time
                                            // the timer event goes off (every five seconds)
                                            // it will set the timer back to five seconds
                                            // so it will keep repeating the timer event
    }
    
    on_rez(integer reznum)      // this part is added to reset the script so the script
                                // knows it has a new owner
    {
        llResetScript();        // this will reset the script
    }
    
} // end of state



// Notes:
// The attach(key id) part automatically checks to see what avatar it is attached to
// so the permissions could be set differently like this:
//
// attach(key id)
// {
//     llRequestPermissions( id, PERMISSION_TRIGGER_ANIMATION );
// }
//
// This alternate method would allow the script to function without the need for a
// llResetScript in the on_rez event since it is not checking the owner, but automatically
// checking the key of the person wearing the attachment.

Owner Only Example: this script will give an example on how to make things work only for the script's owner.
// This example script will play a sound only if the owner of the object touches it.

string sound = "6cb2d20d-229f-fe66-97fc-dd2cc4c0bc42";      // setting the UUID of the sound to be played first
                                                            // it's at this spot in the script mostly for
                                                            // easy reference and access in case it needs to
                                                            // be changed to something else.

default
{
    // since this script will depend on knowing who its owner is then it must be reset somehow
    // to make certain if it becomes owned by someone else it will reset all the values retrieved
    // from llGetOwner()
    
    on_rez( integer reznum)     // on_rez event will happen every time the script is rezzed
    {
        llResetScript();        // this resets the script
    }


    // now to the touch stuff.
    // what needs to happen here is this:
        // perform a check to see if the avatar that touched the box is the owner
        // if it's the owner then the script will play the sound
        // if it is not the owner it will say in chat it has been touched by someone other than
        // the owner.
    
    touch_start(integer total_number)
    {
        if ( llDetectedKey(0) == llGetOwner() )         // this compares the key of the person who clicked
                                                        // to the key of the owner of the script
                                                        // so if they are the same then the if statement
                                                        // is true and it will do everything in the following
                                                        // set of brackets.
        {   // beginning of if statement commands
            llTriggerSound(sound, 1.0);         // this plays the sound (declared earlier in the script
                                                // at full volume. volume for sound playing goes anywhere
                                                // from 0 to 1.
                                                // if a sound string wasn't declared earlier then this
                                                // would like like this:
                                                        // llTriggerSound("name of sound to play", 1.0);
        }   // end of if statement commands
        
        // that's it for playing the sound. now since it is going to do stuff if it wasn't the owner
        // an else statement can be used. this will happen every single time the script looks at the if
        // statement and finds it to be false.
        
        else
        {       // beginning of else bracket
            llSay(0, "Hey, you're not my owner!");
        }       // end of else bracket
    }   // end of touch
}

Variables Example
// this script will add 1 to x every other time it is touched.

integer x = 8;      // this makes an integer set to the value of eight when the script starts
integer y = FALSE;  // you can set integers to TRUE or FALSE too
                    // in this example, y is going to be used to see if the last time the object
                    // was clicked 1 was added to x.
                    // basically by setting y to TRUE and FALSE the script will be able to add one
                    // to x every other time



default
{
    state_entry()       // we'll just have the script say the value of x when it loads
    {
        llSay( 0, "x has a value of: " + (string)x );
    }
        
    touch_start(integer total_number)
    {
        if ( y == FALSE )           // first time clicked y would be false so that's when 1 
                                    // should be added to x                                    
        {
            x = x + 1;              // adding one to x here
            llSay( 0, "1 added to x. x is now: " + (string)x );  // this will make the object say the value of x.
            
            y = TRUE;               // since this started with y being FALSE, now it's time
                                    // to make it TRUE so the next time it's clicked it does
                                    // something different.
        }
        
        else if ( y == TRUE )       // do this stuff is y is TRUE
        {
            llSay( 0, "nothing added to x this time. x is still: " + (string)x );   // object says this
            y = FALSE;          // since nothing was added this time then set y back to FALSE
                                // so something gets added next time.
        }
    }
}
HomePage
There is no comment on this page. [Display comments/form]