Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help needed for a simple listner

yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
06-29-2008 04:05
I am owner and Mistress of sound of a Battlestar Galactica Simulator called BSG21

I've been setting up our Combat Information Center with a number of scripts that utilize sound in a a few ways.

They loop a sound, like an alert klaxon to let people know the ship is in danger, stuff like that.

Thing is the battlestar is kind of big and people can't hear the alert from one end of the battlestar to the other.

Now I realize listeners can be really bad for sim performance.

I think one or two listeners that repeat sound should do the trick.

I'm hoping to build a 1 prim listener that pretty much accepts and replays whatever sound the master button tells it to play

But I'm open to ideas.

Few things I need.

1) Basic code to build a listener that listens for instructions on one channel. There is actually stuff other people did in my sim that I can look at but I want to see some ideas on how its done.
2) Code that I can insert into my master button that will tell the listener, which is essentially a PA system what to do.

I'm hoping to avoid having to stick the audio files in the repeaters, and believe I can probably get around this with UUID passes. The repeater will have to basic functions: loop and one time play.

Simple? Certainly possible, I'm scaring myself with LSL abilities already.

TIA.
Free tour and viper flights for anybody that helps out and wants to see. BSG21 is a Mercury Class Battlestar with fully functional upside down landing decks.

We also might wish to use the same system, probably a few more listeners to handle such issues as damage effects, visual and audio.

This is starting to sound fun isn't it?
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
06-29-2008 04:26
This doesn't even pretend to be anything other than pseudo-code to show how to arrange the lsl function calls. Good luck.

# klaxxonChan - a shared channel number for use by master and slaves
const int klaxxonChan = 4959595; // arbitrary shared number != 0

# in master.lsl
...
key soundKey = llGetInventoryKey("name of sound item in inventory";);
...
touch(int c) {
llShout(klaxxonChan, (string) soundKey);
}


# in slave.lsl
...
// maybe in a entry() event or initializing function
int listenHandle = llListen(klaxxonChan, "", NULL_KEY, "";);
...
listen(int chan, string n, key k, string msg) {
llPlaySound((key) msg, 1.0);
}
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
06-29-2008 04:41
Thanks Malachi Petunia

Fast response and psuedo code can help me and others.

We really want to limit the amount of listeners in the sim.

Working examples appreciated.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-29-2008 04:44
Since the starship is very big I would prefer llRegionSay for llShout. It is faster and lesser load on the SIM too
_____________________
From Studio Dora
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
06-29-2008 04:52
Thanks Dora Gustafson,

I'm starting to wrap my brain around it.

I'm wondering which is more efficient, storing the sound in the repeater or passing it through the sim.

Thinking.

Commander
BSG 21
Mecury
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-29-2008 04:54
From: yevka Laws

Working examples appreciated.

"Welcome to the Free Scripts Gift Shop"
_____________________
From Studio Dora
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
06-29-2008 05:02
I think people will benefit from this thread.

I did forget to point Dr. Google at this site and will do so now.

Anything I find I will post.

I don't want this done for me. Its much more fun to do it myself.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
06-29-2008 05:12
From: yevka Laws
Working examples appreciated.


Here is the gist.

CODE

// This is for the "master" sound thing. It plays a sound when touched,
// and tells its subordinates to play along.

// Fart from the SL library
string what_to_play = "900bdb8a-a208-1c9b-c08e-c67016bf3069";

// use a big negative made-up number for this, that makes it less
// likely that other objects will be using the same one, and you
// can worry less about lag troubles that way.
integer broadcast_channel = -9802345;

default
{
touch_start(integer total_number)
{
llRegionSay(broadcast_channel, what_to_play);
llPlaySound(what_to_play, 0.5);
}
}


CODE

// This is for the "subordinate" sound things. It plays a sound when
// the master sends it one to play.

// use a big negative made-up number for this, that makes it less
// likely that other objects will be using the same one, and you
// can worry less about lag troubles that way.
// Needs to be the same as what the master uses =)
integer broadcast_channel = -9802345;

integer broadcast_handle; // for llListen

key Owner; // to cache llgetOwner()



Init() {
llListenRemove(broadcast_handle);
Owner = llGetOwner();
broadcast_handle = llListen(broadcast_channel, "", "", "");
}

default
{
state_entry() {
Init();
}

changed (integer change) {
if (change & CHANGED_OWNER)
Init();
}

listen(integer channel, string name, key id, string message) {
if (Owner == llGetOwnerKey(id)) { // only objects with same owner
llPlaySound(message, 0.5);
}
}
}

_____________________
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
06-29-2008 05:14
Thanks Viktoria.

I also found this:

/54/a9/105481/1.html

Yevka
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
07-01-2008 00:36
Based on this code, and some help in world with how a listener function works (its a bit inflexible), I have a working system.

It does audio.
I embedded it in a light fixture and when we are on action stations the lighting switches to red.

I may even ad an enhancement to let it rez damage effects after I learn how to build a simple rezzer that rezzes objects to certain coordinates with a time limit.

Thanks for your help.

I could not have done this without you.

High Five. !!!!
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
07-01-2008 00:49
From: Viktoria Dovgal
Here is the gist.

CODE

// Fart from the SL library
string what_to_play = "900bdb8a-a208-1c9b-c08e-c67016bf3069";


hehehe, is that really a fart sound? :)
_____________________
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
07-01-2008 01:28
I never played the fart sound.

My first try with the script used an actual sound I uploaded from the Pegasus episode of Battlestar Galactica.

I will happily demo the system. I'm still working on the code and it belongs to the simulator so posting the whole thing will be a problem.

Helping out others with issues like this will happen.

search for BSG21 to find us and ask someone for a raptor ride to the battlestar.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
07-01-2008 02:05
From: Dekka Raymaker
hehehe, is that really a fart sound? :)

That's LL for you. Farts are OK for the library, but nipples are to be feared.
_____________________