Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with multi-button HUD communication?

Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
11-10-2007 18:50
Hi -

I'm trying to script an object that will receive commands from a 4-button HUD. Button 1 turns the object invisible, buttons 2-4 rez an object multiple times at slow, medium, and fast rates. My question is - in the script below, I'm not sure how to move from one button push to the next. Will the "while" loops hear the listen message and stop the rezzing of objects the way I have it written? Do I need to stop the "while" loop, or will it stop by itself when the next listen event happens?


default
{
state_entry()
{
llListen(333,"button",NULL_KEY,"";); // listen on channel 333 for the HUD buttons.
}

listen( integer channel, string name, key id, string message )
{
if ( message == "stop" )
{
llSetAlpha(0.0,ALL_SIDES); //make it invisible

}
else if (message == "slow";)
{
llSetAlpha(0.2,ALL_SIDES); /make it visible
while (message == "slow";)
{
llRezObject("thing",llGetPos() + <0, 0, -0.005>, ZERO_VECTOR, ZERO_ROTATION, 1);
llSleep(llFrand(3.0));
}
}

else if (message == "medium";)
{
llSetAlpha(0.2,ALL_SIDES); //make it visible
while (message == "medium";)
{
llRezObject("thing",llGetPos() + <0, 0, -0.005>, ZERO_VECTOR, ZERO_ROTATION, 1);
llSleep(llFrand(2.0));
}
}

else if (message == "fast";)
{
llSetAlpha(0.2,ALL_SIDES); // make it visible
while (message == "fast";)
{
llRezObject("thing",llGetPos() + <0, 0, -0.005>, ZERO_VECTOR, ZERO_ROTATION, 1);
llSleep(llFrand(0.5));
}
}
}
}
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
11-10-2007 23:44
From: Galena Qi
Hi -

I'm trying to script an object that will receive commands from a 4-button HUD. Button 1 turns the object invisible, buttons 2-4 rez an object multiple times at slow, medium, and fast rates. My question is - in the script below, I'm not sure how to move from one button push to the next. Will the "while" loops hear the listen message and stop the rezzing of objects the way I have it written? Do I need to stop the "while" loop, or will it stop by itself when the next listen event happens?
</quote>
What do you mean by move from one button to the next? Do you mean stop the processsing triggered by one button and start the processing triggered by another?

The while loops will not hear the listen message. An event won't interrupt another event in the same script, so that part of your code is wrong. If you want to keep doing something until a button is pushed, you'll need to use a timer event and do the rez there. The button pushes would then just change the variable used to set the delay for the timer.

But rezzing stuff repeatedly like that seems unusual, unless you're doing something like bullets for a gun. Make sure you set the objects temp_on_rez if that's the case.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-11-2007 06:13
Here is a little example script that shows what you need to do:

CODE

// Create 4 prim and then link them together. Drop this in the root prim


integer prim_num;
string prim_name;
vector color;

say(){
llOwnerSay( "Prim name: " + prim_name +
", link #" + (string)prim_num + " touched." );
}
params(){
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, color, 0.6]);
say();
}

default {
touch_start( integer n ) {
prim_num = llDetectedLinkNumber(0);
prim_name= llGetLinkName(prim_num);
if(prim_num == 1){
color = <1, 1, 1>;
params();
llOwnerSay("I am also the Root Prim");
}
if(prim_num == 2){
color = <0, 0, 1>;
params();
}
if(prim_num == 3){
color = <0, 1, 0>;
params();
}
if(prim_num == 4){
color = <1, 0, 0>;
params();
}
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
11-11-2007 11:21
Thanks - I suspected the while loop wouldn't hear the next event, but it seems odd that there isn't another way to do it that doesn't use a timer.

No it isn't a gun, and the physical objects I rez have a die on collision with the ground or other objects, so they won't stick around for long.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-11-2007 11:43
Sorry I read that question wrong:)
CODE

default
{
state_entry()
{
llListen(333,"button",NULL_KEY,""); // listen on channel 333 for the HUD buttons.
}

listen( integer channel, string name, key id, string message )
{
if ( message == "stop" )
{
llSetAlpha(0.0,ALL_SIDES); //make it invisible
llSetTimerEvent(0.0);
}
else{
llSetAlpha(0.2,ALL_SIDES); //make it visible
if (message == "slow")
{
llSetTimerEvent(llFrand(3.0));
}

else if (message == "medium")
{
llSetTimerEvent(llFrand(2.0));
}

else if (message == "fast")
{
llSetTimerEvent(llFrand(1.0));
}
}
}
timer()
{
llRezObject("thing",llGetPos() + <0, 0, -0.005>, ZERO_VECTOR, ZERO_ROTATION, 1);
}
}


BUT>>>>>>>>>>>>> I'm not sure you understand the concept of llFrand correctly. In a case like this there is an even chance that calling "fast" will actually end up being slower then "slow". If instead you are trying to do something like a random number between 2-3 seconds then look back at the wiki and it will show how to use llFrand to get a number in a range. You might even end up with a random number generated that is going to be spitting out objects every 0.0001 seconds or so.

Once you get it working like you want, I would suggest bringing it to an empty island and checking script/total ms time when running this. It could end up being pretty unfreindly to a sim.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
11-11-2007 19:13
Jesse;

If I understand your script correctly, it only rezzes one copy of the item per listen event, at a random time after the HUD button click. That isn't what I'm looking for. I'm trying to start rezzing copies as soon as the button is clicked, and reset the speed after the next click. The randomness is in seconds between rezzing instances.

I realize that the llFrand can cause frequent repeats- my next job is to implement the min/max constraint for that function. Right after I figure out why rezzing a physical object from an attachment makes me dance all over the place like a demented puppet.

One thing at a time :-)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-11-2007 19:52
Once a timer event is declared and started, it keeps repeating at the set frequency until it is stopped by using llSetTimerEvent(0.0) or changed to a different frequency by declaring a different value in the llSetTimerEvent.

Try this, just put this script in a prim and then touch the button on your hud or since I took out "button" you can just type in /333 fast for example and you will see how it works:

CODE

default
{
state_entry()
{
llListen(333,"",NULL_KEY,""); // listen on channel 333 for the HUD buttons.
}

listen( integer channel, string name, key id, string message )
{
if ( message == "stop" )
{
llSetAlpha(0.0,ALL_SIDES); //make it invisible
llSetTimerEvent(0.0);
}
else{
llSetAlpha(0.2,ALL_SIDES); //make it visible
if (message == "slow")
{
llSetTimerEvent(10.0);
}

else if (message == "medium")
{
llSetTimerEvent(3.0);
}

else if (message == "fast")
{
llSetTimerEvent(1.0);
}
}
}
timer()
{
llOwnerSay("timer");
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-11-2007 19:57
And to get it to rez immediately and then continue the timing instead of waiting on the timer the first time you use the neTimed example in the wiki:

http://www.cheesefactory.us/lslwm/timer.htm

Hang in there, you will get it. Keep on posting what you have as you progress and we will keep you on track.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
11-11-2007 20:34
I tried it out and it does what you said, but there is no way to include a random interval in the timer - i.e. something like llSetTimerEvent(llFrand(f) + 1.0); won't work since as you say, this keeps the same repeat frequency until it is called again. For my script, I need the random timing.

Unless I include llSetTimerEvent in a loop to call it over and over again, but I don't think that's a good idea since it would really load up the event queue. Hmmm, how to do this?

I really appreciate the help!
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
11-11-2007 21:12
From: Galena Qi
there is no way to include a random interval in the timer
Call llSetTimerEvent with a new randomly-generated interval at the end of each timer event handler. Then again, depending on how much of a differential you want in the interval, a "static" timer value might be good enough, as the actual interval between events can vary quite a bit, depending on server load.

From: someone
Unless I include llSetTimerEvent in a loop to call it over and over again, but I don't think that's a good idea since it would really load up the event queue.
No, that won't work, but it won't load up the event queue, either. You'll just stay in the loop and never reach the next timer event. Calling llSetTimerEvent doesn't add another event to the queue, it just resets the interval until the next timer event is raised (or cancels it altogether).
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
11-11-2007 21:21
I figured it out! Right now it only works well for the "fast" setting. Modifying Jesse's script to add a random element to the time event:

default
{
state_entry()
{
llListen(333,"",NULL_KEY,"";); // listen on channel 333 for the HUD buttons.
}

listen( integer channel, string name, key id, string message )
{
if ( message == "stop" )
{
llSetAlpha(0.0,ALL_SIDES); //make it invisible
llSetTimerEvent(0.0);
}
else{
llSetAlpha(0.2,ALL_SIDES); //make it visible
if (message == "slow";)
{
llSetTimerEvent(10.0);
}

else if (message == "medium";)
{
llSetTimerEvent(3.0);
}

else if (message == "fast";)
{
llSetTimerEvent(1.0);
}
}
}
timer()
{
integer n;
float f = llFrand(5.0);

if (llRound(f) == n)
{
llOwnerSay("timer";);

}
n = n + 1;

if (n > 5)

n = 0;

}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-11-2007 21:56
if you want a timer with a random interval why not this?

//-- in globals
float your-range-here = 2.0; //-- example value, change to suit
float your-min-calc-time = 3.0; //-- example value, change to suit

//-- in start triggering code
llSetTimerEvent( llFrand( your-range-here ) + your-min-calc-time );

//-- in change rate code
your-range-here = some-value;
your-min-calc-time - some-other-value;

timer(){
llSetTimerEvent( llFrand( your-range-here ) + your-min-calc-time );
//--do stuff
}

make sure to figure you minimum calc time as TotalDelays + overhead

using that you can change both your range and you minimum values for different results
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
11-11-2007 22:15
Void;

Is resetting the llTimerEvent frequency every second or two a bad thing lag-wise? If not, your method would work well for me.