Jump to content

Touch Color Change Script


Dadreena Jewell
 Share

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

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

Recommended Posts

Hi everyone,

I have a simple color change script that starts when you touch it. How do I change it from touch to automatic?

In other words, I'd like to put the script into something and the colors just change automatically without me having to touch it to activate.

Thanks so much in advance for your help :)

Link to comment
Share on other sites

I'm not sure exactly what you are trying to do, but it sounds like "automatically" means "continuously," so that the object keeps changing from red to green and back to red every few seconds, for example.  If that's the case, you just need to put your toggle switch into a timer event instead of the touch_start event.  So, if your touch_start event looks something like this now

touch_start(integer num)
{
    llSetColor( llList2Vector([<1.0,0.0,0.0>,<0.0.1.0,0.0>], (iSwitch = !iSwitch) ), ALL_SIDES);
}

then you just put the equivalent code into a timer event:

timer()
{
    llSetColor( llList2Vector([<1.0,0.0,0.0>,<0.0.1.0,0.0>], (iSwitch = !iSwitch) ), ALL_SIDES);
}

Just remember to make the toggle variable, iSwitch, a global integer, and to start the timer someplace like the state_entry event with

llSetTimerEvent(5.0);  // or whatever timer interval you like.

  • Like 1
Link to comment
Share on other sites

Hi there,

~{NOTE}~
========
This script will make your object able to change it's color every 2nd sec.

If you touch it once it will trigger the color-changing functionality,
and if you touch it again it will reset itself.

it will respond to your commands only.
I hope this helps.

PS: u can modify the speed of the color switching function by editing the gap variable.
cheers.

~{USER GUIDE}~
==============
1. right-click on the object.
2. edit.
3. choose the content tab.
4. click: new script.
5. open the script (called 'New Script').
6. paste the code below.
7. save.
8. left click on the object to trigger the script.

float gap = 2.0;
integer counter;

default
{
    touch_end(integer n)
    {
        key objOwnerKey   = llGetOwner();
        key objTriggerKey = llDetectedKey(0);
        if (objOwnerKey == objTriggerKey)
        {
            state timer_state;
        }
    }
}

state timer_state
{

    state_entry()
    {
        llSetTimerEvent(gap);
    }

    timer()
    {

        if (counter == 0)
        {
            llSetColor(<1.000, 1.000, 1.000>, ALL_SIDES);
            counter = 1;
        }

        else if (counter = 1)
        {
            llSetColor(<0.067, 0.067, 0.067>, ALL_SIDES);
            counter = 0;
        }

    }

    touch_end(integer n)
    {
        key objOwnerKey   = llGetOwner();
        key objTriggerKey = llDetectedKey(0);
        if (objOwnerKey == objTriggerKey)
        {
            state default;
        }
    }

    state_exit()
    {
        llSetColor(<1.000, 1.000, 1.000>, ALL_SIDES);
        llSetTimerEvent(0.0);
        counter = 0;
    }

}

  • Like 1
Link to comment
Share on other sites

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