Jump to content

Transparency and Colour Rotation Help please


Starla Metaller
 Share

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

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

Recommended Posts

Hi, I am new to scripting, but there are two elements that I would like to apply to some of the objects on my build:

1) apply some kind of transparency loop - so the object appears to fade in and out by itself (I'm trying to create the effect of a projection)

2) apply a rotation between two colours - again on a loop

Thank you very much!

Link to comment
Share on other sites

Check out llSetLinkAlpha to fade an object in/out  - see Wiki, there is even a small sample.

For a little good color change sample, check Wiki on llSetColor - now you write rotation between colors, I assume, you just mean changing between say two colors colors. Else it is normally understood as fading colors into each other based on for example an color wheel using RGB values, which is more complex to do.

If you are very new to scripting in SL, use a little time to study the Tutorial, both things you want to make are excellent beginner training to do in LSL.

 

Link to comment
Share on other sites

Thank you - is there another command I could use instead of Touch_Start to have the fade in/out happen automatically on a loop, or failing that when it detects an avatar?

And yes, I want to change between two colours (sorry for not being clear).  I'm not sure which bits of the colour script I should remove or change to go from say, aqua to fuschia?

 

Thanks again :-)

 

Link to comment
Share on other sites

Begin by doing the tutorials that Rachel suggested.  Until you do that, all you're doing is blindly stuffing functions into scripts that you don't understand. If something works, you'll have no idea why it does.  More likely, you'll just get frustrated.

For now ....  touch_start is not a "command".  It is an event, a group of statements that describe what you want your scripted object to do when someone clicks on it.  When you do the tutorials, you will learn that there are many different sorts of events available to you in LSL.  From your description, it sounds as if you will want to write a script with either a timer event or a sensor event to do the work.  Then you will want your script to include ways to trigger the event (by turning on the timer or activating a sensor).  Those concepts should become clearer when you have done the tutorials and had some time to think and practice.

As far as color is concerned ..... Color in any scripting environment is described by a three-component vector that describes the mix of red, green, and blue that make up the desired hue.  So, changing color is a matter of writing a script that manipulates a color vector, <r, g, b>.  In LSL, each of the three components is a number between 0.0 and 1.0, so pure red is <1.0, 0.0, 0.0>, pure green is <0.0, 1.0, 0.0>, and pure blue is <0.0, 0.0, 1.0>. You can see what effect changing those numbers together will have by looking at http://wiki.secondlife.com/wiki/Category:LSL_Color .  To apply a specific color, your script will use a function like llSetColor.  To make colors change gradually between two selected hues, you will need to do some magic in a timer event that changes components in the color vectors incrementally with each time step.  This is not a particularly hard thing to do, but again, it won't make sense to you until you have done some basic tutorials to get a feel for how LSL works and have had some practice.

There are two approaches to learning how to script.  One is to begin with a project in mind, find existing scripts that do something close, and modify them to reach your goal.  The other is to start with a clean slate, learn the structure of the scripting language, and build simple scripts that you can then combine to make something beautiful. Most of us actually learned by using both approaches.  Doing one or the other by itself is either frustrating or annoyingly slow.  So what I am recommending is enough tutorial stuff to get the basic concepts down while you examine specific functions and sample scripts that will help create your first project.  Experiment.  When you get stuck, come here with a specific question.

  • Like 1
Link to comment
Share on other sites

Well, some basics to get you on the way, example on changing color, when you touch the object, bump into it and automatic change based on a timer- but study the tutorials.

vector green    = <0.180, 0.800, 0.251>;
vector red      = <1.000, 0.255, 0.212>;

integer bToggle = FALSE;

toggleColors()
{
        bToggle= !bToggle;
        
        if (bToggle)
        {
            llSetColor( green, ALL_SIDES);
        }
        else
        {
            llSetColor( red, ALL_SIDES);
        }
}

default
{
    state_entry()
    {
        // call timer every 15 second
        llSetTimerEvent(15.0);
    }

    touch_start(integer total_number)
    {
        toggleColors();
        
        llSay(0, "You touched me...");
    }
    
    collision_start(integer num)
    {
        toggleColors();
        llSay(0, "You bumped into me...");
    }
    
    timer()
    {
        toggleColors();
        llSay(0, "Timer changed colors...");
    }
}

 

Edited by Rachel1206
  • Like 1
Link to comment
Share on other sites

Hi, I am working on the transparency script (and leaving the colour changing script for the time being).

I've put some bits together from a few of the scripts that I have seen in the tutorials, but cannot get it quite right.  I wonder if you could take a look and see what I might be doing wrong?

The script below is doing a nice job of fading the object in and out repeatedly when an avatar is near.  I would like it to stay transparent for a little longer (say 2s) before returning to it's previous state.  I've tried adding a timer, but I think I may be missing something? (I'm trying to create the impression of a flickering projection).

integer counter;

float   gap = 2.0;

 

default

{

 

    state_entry() {

        llSensorRepeat("", NULL_KEY, AGENT, 10, PI, 5);

        llSetTimerEvent(gap);

    }

    sensor(integer total_number) {

 

        // fade out

        float alpha = 0.3;

        while (alpha >= 0.0)

        {

            llSetLinkAlpha(LINK_SET, alpha, ALL_SIDES);

            alpha -= 0.001;

        }

 

        // fade in

        while (alpha < 0.3)

        {

            alpha += 0.001;

            llSetLinkAlpha(LINK_SET, alpha, ALL_SIDES);

        }

    }

}

Link to comment
Share on other sites

You're going to have to use a timer.  As written, the loops is your sensor event will go as fast as lightning ... essentially instantaneously, or as fast as the servers will let them go.  You could fake a timer by introducing a llSleep each time you enter a new step in each loop, but that will be really counterproductive.  llSleep does exactly what it says; it puts the script completely to sleep for the duration of the sleep period. That means it will be unable to sense or respond to any other input during that time.  It's much smarter to use an actual timer event.

Remember that you cannot interrupt an event, hopping out and back into it.  An event completes all of its activity before releasing control to any other event. Therefore, you will need to trigger the timer in your sensor event but put all of the fade in / fade out stuff into the timer event.  You may of course stop the timer after a cycle and then restart it for another cycle, thus separating the fade in and fade out periods.  That's simply a matter of installing a toggle switch in the timer to change its behavior at points you designate.

Link to comment
Share on other sites

Since you are new to scripting, here is an example of how to do what you want...

you can change the line..... flag = ( ++flag % 3 )   to use % 4, %5 etc , for a longer pause..

 

float   gap = 2.0;
float alpha = 0.3;
integer toggle;
integer flag = -1;
default
{
    state_entry()
    {   llSetLinkAlpha(LINK_SET, 0.3, ALL_SIDES);
        llSensorRepeat("", NULL_KEY, AGENT, 10, PI,2);       
    }
    sensor(integer total_number)
    {  if ( toggle == FALSE )  //  toggle is false, switch it to true and only trigger the timer ONCE when someone is in range
       {    toggle = TRUE;     // toggle is now true, and the IF above will not fire again untill reset
            llSetTimerEvent(0.2); 
       }
    }
    no_sensor()  // reset all variables and turn off timer fading
    {    alpha = 0.3;
         llSetLinkAlpha(LINK_SET, alpha, ALL_SIDES);        
         flag = -1;
         toggle = FALSE;
         llSetTimerEvent(0.0);
    }
    timer()
    {   flag = (++flag % 3);    // add one to the flag variable ... (++flag % 3) ... will loop from 0 to 2 and start at 0 again 
        // fade out      
        while (alpha >= 0.0)
        {   alpha -= 0.0001;  // adjust alpha BEFORE setting it
            llSetLinkAlpha(LINK_SET, alpha, ALL_SIDES);   
        }
        if( flag == 2 )  // every GAP seconds the flag gets increased until it reaches 2 .... this is when the fade IN happens  ONLY when flag is 2
        {  // fade in
           while (alpha < 0.3)
           {   alpha += 0.0001;
               llSetLinkAlpha(LINK_SET, alpha, ALL_SIDES);
           }
        }
         llSetTimerEvent(gap);
    }
} 

 

Edited by Xiija
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2377 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...