Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

interrupt for/while with touch/link?

bucky Barkley
Registered User
Join date: 15 May 2006
Posts: 200
09-05-2006 22:48
I have a nice effect involving scrolling text in llSetText() with
substrings ... I would like to be able to interrupt the loop that
drives it via a touch or link event. Is this possible? My impression
so far is that LSL stacks things up in the event queue
(a touch_start() triggers the scrolling.. so what I am basically
asking is "how to interrupt the handling of the current event"?)
Adriana Caligari
Registered User
Join date: 21 Apr 2005
Posts: 458
09-05-2006 23:11
Correct - they are Queued - so once your in a while not a lot will interrupt it.

The best way ( in my opinion ) is to start the while manually , then continue it in a timer loop.

eg
CODE


begin()
{
condition = TRUE;
llSetTimerEvent( delay ) ;
}
.
.
timer()
{
if ( condition )
{
// do something
}
else
{
llSetTimerEvent(0); //switch off the timer afteryour finished
}
}
_____________________
Maker of quality Gadgets
Caligari Designs Store
Archanox Underthorn
Registered User
Join date: 20 May 2003
Posts: 168
09-06-2006 10:05
Just throwing another idea out there, you could possibly have a second script in the object that when touched changes the objects description to a certain phrase. Then you could change the while loop to something like:

while(condition1 && llGetObjectDesc() != "stop";)
_____________________
Archatek

Home to some of the highest quality katanas and other blades available in SL. Co-creator of the Samurai Island Combat System, one of the best melee combat systems available, come check it out!

___________________
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-06-2006 10:34
Ooh, that's a great idea. I'll have to remember that one :)
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
09-06-2006 11:20
I have a script I wrote the other day that does something similar. What I did was step it using a timer.. Unfortunately it tends to cause lag, so I use this very sparingly.. I'll have to find a way to make it less laggy.

CODE

key keyOwner; // This is the owenr of the object
float fltTypeRate = 0.1; // How fast we're gonna step through
integer intFadeSteps = 10; // How many steps in fading away
integer intPauseSteps = 15; // How many timer events we'll pause for
vector clrColor = <1, 1, 0>; // Color of Text

float fltAlpha = 1.0; // Used for fading away
integer intStep = 0; // Which step we're on in any paticular stage - ReUsable
integer intStage = 0; // Keep track of where we are in the three stage animation
string strText; // The name of the owner of this script

fnInit()
{
keyOwner = llGetOwner();
strText = llKey2Name(keyOwner);
}

default
{
state_entry()
{
if (keyOwner != llGetOwner()) { fnInit(); }
llListen(0, "", keyOwner, "");
}

on_rez(integer intParam)
{
if (keyOwner != llGetOwner())
{
fnInit();
}
}

listen(integer intChan, string strName, key keyID, string strMsg)
{
if (llToLower(strMsg) == "t on")
{
state on;
return;
}

if (llToLower(strMsg) == "t hide")
{
llSetAlpha(0.0, ALL_SIDES);
return;
}

if (llToLower(strMsg) == "t show")
{
llSetAlpha(1.0, ALL_SIDES);
return;
}

if (llToLower(strMsg) == "t name")
{
strText = llKey2Name(keyOwner);
return;
}

if (llToLower(strMsg) == "t afk")
{
strText = "Away From Keyboard.";
return;
}

if (llToLower(strMsg) == "t script")
{
strText = "Scripting. Leave Message.";
return;
}
}
}

state on
{
state_entry()
{
fltAlpha = 1.0; // Reset Alpha
intStep = 0; // Reset Step
intStage = 0; // Reset Stage

llSetText("", clrColor, fltAlpha);
llSetTimerEvent(fltTypeRate);
llListen(0, "", keyOwner, "");

llSay(0, "Activated!");
}

listen(integer intChan, string strName, key keyID, string strMsg)
{
if (llToLower(strMsg) == "t off")
{
state default;
return;
}

if (llToLower(strMsg) == "t hide")
{
llSetAlpha(0.0, ALL_SIDES);
return;
}

if (llToLower(strMsg) == "t show")
{
llSetAlpha(1.0, ALL_SIDES);
return;
}

if (llToLower(strMsg) == "t name")
{
strText = llKey2Name(keyOwner);
return;
}

if (llToLower(strMsg) == "t afk")
{
strText = "Away From Keyboard.";
return;
}

if (llToLower(strMsg) == "t script")
{
strText = "Scripting. Leave Message.";
return;
}

}

timer()
{
if (intStage == 0)
{
llSetText(llGetSubString(strText, 0, intStep), clrColor, fltAlpha);

if (++intStep >= llStringLength(strText))
{
intStep = 0; // Reset the shown number
intStage = 1; // Move onto next stage
}
}

else if (intStage == 1)
{
if (++intStep >= intPauseSteps)
{
intStep = 0; // Reset the Pause
intStage = 2; // Move onto next stage
}
}

else if (intStage == 2)
{
fltAlpha -= (1.0 / intFadeSteps);

llSetText(strText, clrColor, fltAlpha);

if (fltAlpha <= 0.0)
{
fltAlpha = 1.0; // Reset Alpha
llSetText("", clrColor, fltAlpha); // Reset the Floating Text
intStage = 3; // Move onto next stage
}
}

else
{
if (++intStep >= intPauseSteps)
{
intStep = 0; // Reset the Pause
intStage = 0; // Move onto next stage
}

}
}

state_exit()
{
intStep = 0; // Reset the Steps
intStage = 0; // Reset the Stage
fltAlpha = 1.0; // Reset the Alpha
llSetText("", clrColor, fltAlpha); // Reset the Floating Text

llSay(0, "DeActivated!");
}
}


Feel free to tweak it.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-06-2006 11:26
From: Archanox Underthorn
Just throwing another idea out there, you could possibly have a second script in the object that when touched changes the objects description to a certain phrase. Then you could change the while loop to something like:

while(condition1 && llGetObjectDesc() != "stop";)

Yeah. Other properties of the prim can be used similarly: color (of a certain side), alpha (of a certain side), name, description, primitive parameters, position, velocity, etc. Which is best depends on the exact application. However, I think this case is likely best handled with timers. A tight loop is not necessary (like it is in some non-physical movement cases, for example) and may deprive the sim of some event processing time. Unless you've got all speedreaders as users, every 0.05 to 0.1 seconds or longer should be plenty sufficient to change the text, don't you think? :-)
bucky Barkley
Registered User
Join date: 15 May 2006
Posts: 200
thanks for suggestions
09-07-2006 09:55
I like the idea of checking for alpha on a non-visible side. Thanks all for the suggestions! It's cool that using a 0-100 or 0-255 range works out to be a useful for a protocol.

I haven't seen so much sheer hackery since I did Atari Basic with 16k long ago :-)
(oh oh, just dated myself!)

The app is for a picture frame - I scroll text (photo descriptions), but want
to be able to interrupt to go to prev/next photos. I have an in-world show
coming up that I'll comment on more when I have details.

Note to Lindens: Provide a per-prim 256 byte dedicated scratchpad.