ImojenSander Posted April 28, 2016 Share Posted April 28, 2016 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 More sharing options...
Freya Mokusei Posted April 28, 2016 Share Posted April 28, 2016 I always liked the LSL example from LSLWiki.net for explaining the Listen event to people. Once you initiate a listener (using llListen), you can test for specific words or phrases being spoken on channel 0 - the local channel - by testing against string message. Hope this helps! Link to comment Share on other sites More sharing options...
Ice12192 Dover Posted April 28, 2016 Share Posted April 28, 2016 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 More sharing options...
Qie Niangao Posted April 28, 2016 Share Posted April 28, 2016 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 More sharing options...
ImojenSander Posted April 28, 2016 Author Share Posted April 28, 2016 ok thanks for all ur help n advise iv got it working great thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
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