Jump to content

locking a fade


ImojenSander
 Share

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

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

Recommended Posts

hi i have a script to fade out an object then click to fade back in again. What im looking for is how to say in local chat 'lock' or 'unlock' so it stops fade out when clicked. heres the script.

  touch_end(integer total_number)
    {
        float alpha = 1.0;
        while(alpha > 0.0)
        {
            alpha -= 0.1;
            llSetAlpha(alpha, ALL_SIDES);
            llSleep(cloakSpeed);
        }
        state cloaked;
    }
}
 
state cloaked
{
    touch_end(integer total_number)
    {
        float alpha;
        while (alpha < 1.0)
        {
            alpha += 0.1;
            llSetAlpha(alpha, ALL_SIDES);
            llSleep(cloakSpeed);
        }
        state default;
    }
}

thanks

Link to comment
Share on other sites

Hi,

 

Here is some code that might be able to help you

 

float cloakSpeed = 0.5;float alpha = 1;integer listener;string status = "STOP";default{	state_entry()	{		listener = llListen(0, "", llGetOwner(), "");		llSetTimerEvent(cloakSpeed);	}	state_exit()	{		llListenRemove(listener);		llSetTimerEvent(0.0);	}	listen(integer channel, string name, key id, string message)	{		if(message == "lock") {			status = "LOCKED";		} else if(message == "unlock") {			status = "UNLOCKED";		}	}	timer()	{		if(status == "UNLOCKED") {			alpha -= 0.1;			llSay(0, (string)alpha);			llSetAlpha(alpha, ALL_SIDES);			if(alpha < 0.1) {				alpha = 0;				status = "LOCKED";				state cloaked;			}		}	}	touch_end(integer total_number)    {        status = "UNLOCKED";    }} state cloaked{    state_entry()	{		listener = llListen(0, "", llGetOwner(), "");		llSetTimerEvent(cloakSpeed);		llSay(0, "Cloaked");	}	state_exit()	{		llListenRemove(listener);		llSetTimerEvent(0.0);	}	listen(integer channel, string name, key id, string message)	{		if(message == "lock") {			status = "LOCKED";		} else if(message == "unlock") {			status = "UNLOCKED";		}	}	timer()	{		if(status == "UNLOCKED") {			alpha += 0.1;			llSetAlpha(alpha, ALL_SIDES);			if(alpha > 0.9) {				alpha = 1;				status = "LOCKED";				state default;			}		}	}	touch_end(integer total_number)    {        status = "UNLOCKED";	}}
Link to comment
Share on other sites

Inherited from the OP's script, this is a pretty good demonstration of why states usually make a script larger, less efficient, and harder to understand. Here, using a second state instead of a simple global variable doubles the script length.

The important change here, in addition to a listen, is replacing the llSleep loop with a timer event to make it possible to intervene part-way through fading.

Link to comment
Share on other sites

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