Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problems with a simple sound loop

yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
04-21-2008 14:32
I uploaded a 7 second sound clip for a sim I'm building.

I'm a beginner scripting but had a basic goal.

I want this sound to repeat in a loop, run around 60 seconds then stop.

Its an Alert klaxon for a Battlestar

I created aprim box and stuck the sound inside.

then a script to play it.

Here are my tries:

default
{
state_entry()
{
llSay(0, "Action Stations! Action Stations! Set Conition 1 throughout the ship!";);
}

touch_start(integer total_number)
{
llSay(0, "Action Stations! Action Stations! Set Conition 1 throughout the ship!";);
llSay(0, "All pilots report to the launch bay.";);
integer x = 0;


llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1);
llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1);
llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1);
llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1);
llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1);
llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1);




}
}

plays the sound once and exits.


For loop:

default
{
state_entry()
{
}


touch_start(integer total_number)
{
integer x = 0;

for (x = 0; x < 10; x++)
{

llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1);

}
}
}

I put a write statement with a number in the for loop and it executes 10 times and then the sound plays.

Have mercy on me, I'm learning scripting the hard way.

Can someone tell me how to do this so my script controls how long the sound loops.
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
04-21-2008 16:11
try llLoopSound, then start a timer which after 60 seconds (or whatever) does llStopSound.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llLoopSound
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetTimerEvent

The reason for the current behavior is a couple of things:

- bunches of llPlaySound commands or loop routines will execute as fast as possible, they don't wait for the current sound to stop playing before trying again

- a prim can only be playing one sound at any given time


You could in theory make either script pause between iterations by inserting llSleep in there, but llLoopSound is pretty much made for this :)

Hope that helps some.
_____________________
Designer of sensual, tasteful couple's animations - for residents who take their leisure time seriously. ;)

http://slurl.com/secondlife/Brownlee/203/110/109/

Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-21-2008 16:26
EDIT: ahhhh Cool Anti!!!! Don't ever play with sound and never noticed llLoopSound before. Be back in a minute with a different incarnation using it.

CODE
integer cntr;
string sound;

default {
touch_start(integer total_number) {
sound = llGetInventoryName(INVENTORY_SOUND, 0);
cntr = 8;
llSay(0, "Action Stations! Action Stations! Set Condition 1 throughout the ship!");
llSay(0, "All pilots report to the launch bay.");
llPlaySound(sound, 1);
llSetTimerEvent(7.0);
}
timer() {
if(cntr > 0){
llPlaySound(sound, 1);
cntr--;
}
else{
llSetTimerEvent(0.0);
}
}
}

This will immediately play the sound when touched and then repeat 8 more times (every 7 seconds) for a total of 63 seconds.



Much nicer:
CODE

default {
touch_start(integer total_number) {
string sound = llGetInventoryName(INVENTORY_SOUND, 0);
llSay(0, "Action Stations! Action Stations! Set Condition 1 throughout the ship!");
llSay(0, "All pilots report to the launch bay.");
llLoopSound(sound, 1);
llSetTimerEvent(60.0);
}
timer() {
llStopSound();
}
}
_____________________
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
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
04-21-2008 16:33
wow - that's quite a relief to know, that even the cracks here don't know all commands :)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-21-2008 16:36
From: Haruki Watanabe
wow - that's quite a relief to know, that even the cracks here don't know all commands :)

Heck I thought I had em all memorized. Guess I am going to have to get my print out of the wiki and put it back in the magazine rack in the bathroom again for studying.
_____________________
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
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
04-21-2008 16:53
Aww, all the points go to Jesse for providing a complete working example and, well, just being Jesse. Helpful and gracious as ever.

Glad I was able to chip in a bit. Too bad I'm not into the whole RP/family/children thing, or I'd surely tell my grandkid avatars about the time I was quicker on the trigger than Mr. Barnett with an LSL command :D
_____________________
Designer of sensual, tasteful couple's animations - for residents who take their leisure time seriously. ;)

http://slurl.com/secondlife/Brownlee/203/110/109/

Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-21-2008 17:43
From: Anti Antonelli
Aww, all the points go to Jesse for providing a complete working example and, well, just being Jesse. Helpful and gracious as ever.

Glad I was able to chip in a bit. Too bad I'm not into the whole RP/family/children thing, or I'd surely tell my grandkid avatars about the time I was quicker on the trigger than Mr. Barnett with an LSL command :D

Ms Barnett :) (Don't feel bad, our hedgehog and I get that a lot!)

I still remember the one and ONLY time I had a script that run a little bit faster then one of Strife's. OMG, I was on cloud 9 for days afterwards. Must have been a combination of alignments of the planets, a fast day for me and an off day for him.
_____________________
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
Laurence Corleone
Registered User
Join date: 12 Oct 2006
Posts: 126
04-21-2008 19:17
From: Jesse Barnett
Heck I thought I had em all memorized. Guess I am going to have to get my print out of the wiki and put it back in the magazine rack in the bathroom again for studying.


A girl after my own heart. Not just put it in the magazine rack in the bathroom but put it in the magazine rack in the bathroom _again_ :D
_____________________
There are no stupid questions, just stupid people.
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
04-21-2008 19:56
Ack, sorry Jesse :o
_____________________
Designer of sensual, tasteful couple's animations - for residents who take their leisure time seriously. ;)

http://slurl.com/secondlife/Brownlee/203/110/109/

yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
So many things to try.
04-21-2008 23:24
Thanks for your input, I will be testing your ideas after some RL.

If anyone has tested their code thats great.

TIA I estimate a test in about 6-8 hours.