Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Prim causing HUD to play sound

Dudeney Ge
EduNation Archipelago
Join date: 21 Jul 2006
Posts: 95
10-05-2007 10:22
Folks,

I have a prim with a sound file in it, and a HUD. When someone collides with the prim it's supposed to tell the HUD to play the sound file...

Prim is as follows:

CODE

integer channel = 5622354;

default
{
state_entry()
{
llVolumeDetect(TRUE);
}

collision_start(integer num)
{
string sounditem = llGetInventoryName(INVENTORY_SOUND, 0);
string soundkey = llGetInventoryKey((string)sounditem);
llSay(channel, (string)llDetectedName(0)+"|"+soundkey);
}

collision_end(integer num_detected)
{
llSay(channel, (string)llDetectedName(0));
}
}



HUD is as follows:

CODE

integer channel = 5622354;
integer listenID;

reset()
{
llListenRemove(listenID);
listenID = llListen(channel, "", NULL_KEY, "");
}

default
{
state_entry()
{
reset();
}

on_rez(integer start_param)
{
reset();
}

listen(integer channel, string nm, key id, string message)
{
if(llSubStringIndex(message, "|")<0)
{
if(message==(string)llGetOwner())
llStopSound();
llOwnerSay("Sound stopped");
}

else
{
list temp=llParseString2List(message, ["|"], []);
if(llList2Key(temp, 0)==llGetOwner())
llLoopSound(llList2Key(temp, 1), 1.0);
llOwnerSay((llList2Key(temp, 1)));
llOwnerSay((llList2Key(temp, 0)));
}
}
}


The llOwnerSay output is what I was expecting, but the HUD remains silent. Why isn't this playing the sound file?

Thanks in advance,

DG
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-05-2007 10:53
at the very end..... your object sends "OwnerNAME|SoundKey"...

but your listen parses and tests for (key)"OwnerNAME" == "OwnerKEY"

just make your object send llDetectedKey( 0 ); instead

EDIT: you did the same test in the stop section... llGetOwner returns the owners key, not their name

RE-EDIT: this is why you should always use brackets... makes debugging easier...

if (test){
//debug = I passed the test
//do stuff
}
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
10-05-2007 10:55
Couple of things. First, the llList2Key shouldn't work from a parsed string message--the list will be a bunch of strings, so I'd try an explicit typecast: (key)llList2String...

Second, I haven't tested this but, because they're both linked to the sound-emitting object's location, I suspect that llLoopSound, like llPlaySound, won't work in HUDs... or, rather, only the wearer should hear the sound. Might try llTriggerSound with some kind of timer (to effect the looping). (Or try it first with the HUD detached and just rezzed on the ground, to make sure it works under those conditions.)
Dudeney Ge
EduNation Archipelago
Join date: 21 Jul 2006
Posts: 95
Working - Next Question...
10-05-2007 11:16
From: Qie Niangao
Second, I haven't tested this but, because they're both linked to the sound-emitting object's location, I suspect that llLoopSound, like llPlaySound, won't work in HUDs... or, rather, only the wearer should hear the sound. Might try llTriggerSound with some kind of timer (to effect the looping). (Or try it first with the HUD detached and just rezzed on the ground, to make sure it works under those conditions.)


Right, thanks to the suggestions is now plays the file when rezzed on the ground (using llLoopSound) and stops immediately the avatar leaves the area.

It also works in the HUD (using llTriggerSound). This is fine - in fact I only want the wearer of the HUD to hear the sound, ideally

The problem now is that llStopSound doesn't work with llTriggerSound so when the avatar leaves the prim area the file plays to the end.

Is it possible to stop it when played from the HUD?

DG
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
10-05-2007 12:50
From: Dudeney Ge
It also works in the HUD (using llTriggerSound). This is fine - in fact I only want the wearer of the HUD to hear the sound, ideally

The problem now is that llStopSound doesn't work with llTriggerSound so when the avatar leaves the prim area the file plays to the end.
Meep. :o I think I led you astray: if only the wearer is to hear it, you probably want llLoopSound after all, in which case llStopSound would stop it. (The llTriggerSound thing was if others were to hear it as if emanating from the wearer.)
Dudeney Ge
EduNation Archipelago
Join date: 21 Jul 2006
Posts: 95
Not So Led Astray
10-05-2007 13:13
From: Qie Niangao
Meep. :o I think I led you astray: if only the wearer is to hear it, you probably want llLoopSound after all, in which case llStopSound would stop it. (The llTriggerSound thing was if others were to hear it as if emanating from the wearer.)


The thing is that only llTriggerSound appears to work in the HUD - I can't get a peep out of llLoopSound or llPlaySound. As it is, I've ideally like the HUD to reproduce the sound only for the avatar wearing it, and to stop when they leave the area of the trigger prim.... but at the moment I'm stumped.

DG