Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

HUd talking to prim and vice versa

Flivelwitz Alsop
Registered User
Join date: 26 Mar 2008
Posts: 6
03-17-2009 11:55
I am wondering, I am making a HUD that triggeres a sound from a prim attached to my avatar (via llSay()). However, it seems that it only triggers the sounds when I rezz the prim first and the HUD second. If I rezz the HUD then rezz the prim, it won't listen. Is there some sort of basic code in the on_rez command in both so it doesn't matter what goes on first? I am using a simple code in the prim:

on_rez(integer s)
{
if(llGetAttached()>0)
{
avatar = llGetOwner();
glistener = llListen(channel, "", NULL_KEY,"";);
}
}

thanks.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
03-17-2009 13:36
You're not showing a complete script. :)

How is the variable 'channel' being assigned? How does the HUD know which channel to use?

Kinda tricky to debug without seeing the full script(s).
_____________________
Flivelwitz Alsop
Registered User
Join date: 26 Mar 2008
Posts: 6
03-17-2009 15:50
Thanks for response - The HUD uses this script to talk to the prim on the avatar:

default
{
on_rez(integer s)
{
channel = (integer) llFrand(10000.0) * -1 - 1;
Channel = channel;
llSay(-5, (string)Channel);
}
touch_start(integer total_number)
{
// Get the name of the prim touched
llSay(channel, llGetLinkName(llDetectedLinkNumber(0)));
}
}

It tells the prim what to channel it's going to send commands on in the on_rez, the prim attached to tthe avatar does this:

default
{
on_rez(integer s)
{
//at the moment it isnt attached....
//if(llGetAttached()>0)
{
avatar = llGetOwner();
glistener = llListen(-5, "", NULL_KEY,"";);
}
}
state_entry()
{
if ( llGetInventoryNumber(INVENTORY_SOUND) == 0 )
{
llOwnerSay("Critical error, no sounds found!";);
}
}
listen(integer channel, string name, key id, string message)
{
if (channel == -5)//listening here (where the HUD first sends on, so it learns what the random channel will be...
{
llListenRemove(glistener);
glistener = llListen((integer)message, "", NULL_KEY, "";);//resetting the channel
}
if (message == "Upper Circle";) // and etc. "Upper Circle" is the name of the prim you touched in the HUD.
.
.
.

I can see here that the attached prim should be attached first (as it's listening and waiting for the HUD to tell it what channel it will be, and the HUD automatically sends the channel but once. But Im not sure how to do it both ways; Maybe I shold move the code in the HUD on_rez into a dialogue box, so it doesn't send until I tell it to. That seems to be a bit "cheap" though... :-)
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
03-17-2009 16:35
I know this doesn't answer the question of why your listener isn't working, but how about this as a quick fix? Have both the hud and the prim listening to
CODE
integer channel() { 
return (integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1))*-1;
}

The odds against there being anything else on the sim listening on a channel based on your uuid are pretty long, I would think. (Unless it's something else you've made, in which case just add a number of your choice to the hud/prim communication channel).
WhiteStar Magic
Build it+Script it=RUN!
Join date: 24 Jul 2008
Posts: 36
03-17-2009 18:15
Just my 2 cents...

When I design a HUD which communicates with an external, I use a Locked -CHANNEL, so both are using the same channel to interact. Random Channels I only use for menus which are dynamic and killed as soon as there is a response or timer event which clears a ListenHandle.

There is another approach which I have used quite successfully The initial Channel is set to -100 in HUD & DEVICE, Both have an active listen running on REZ. a Timer event which sends a query
(Partial Code)
From HUD to DEVICE llWhisper(-100,"HUD_100";),
Response from DEVICE to HUD active listen (llWhisper(-100,"DEV_100";);
The HUD's Listen then grabs
if(channel = -100 && msg="DEV_100";)
{
string DateSeq = llGetDate(); // yyyy-mm-dd format
string DateClean = (llGetSubString(DateSeq,0,3)+llGetSubString(DateSeq,5,6)+DateSeq,8,9));
integer tmpCHAN = (integer)DateClean;
CHANNEL = -tmpCHAN;
llWhisper(-100,"NewChan="+(string)CHANNEL; // Tells Device the new channel
}

So you grab the current date, parse it to remove the " - ", convert that to a NEGATIVE INTEGER and send it to the Device & Keep that as the new active channel in the hud. You can also further sequence that with a TimeStamp Segment.

Also of note.. Kill the timer() function in the HUD once the two way Chat have verified that they are both there and the new Channel has been assigned.

There are many ways to assign channels.
_____________________
Build it, Script it & Enjoy It, then Share it !!!
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
03-18-2009 13:03
You could also use your -5 channel for two way communication...


default
{
on_rez(integer s)
{
glistener = llListen(-5, "", NULL_KEY,"";);
channel = (integer) llFrand(10000.0) * -1 - 1;
Channel = channel;
llSay(-5, (string)Channel);
}
touch_start(integer total_number)
{
// Get the name of the prim touched
llSay(channel, llGetLinkName(llDetectedLinkNumber(0)));
}
listen(integer channel, string name, key id, string message)
{
if (message == "report";) llSay(-5, (string)Channel);
else if (message == "done";) llListenRemove(glistener);
}

}




default
{
on_rez(integer s)
{
//at the moment it isnt attached....
//if(llGetAttached()>0)
{
avatar = llGetOwner();
glistener = llListen(-5, "", NULL_KEY,"";);
llSay(-5, "report";);
}
}
state_entry()
{
if ( llGetInventoryNumber(INVENTORY_SOUND) == 0 )
{
llOwnerSay("Critical error, no sounds found!";);
}
}
listen(integer channel, string name, key id, string message)
{
if (channel == -5)//listening here (where the HUD first sends on, so it learns what the random channel will be...
{
llSay(-5, "done";);
llListenRemove(glistener);
glistener = llListen((integer)message, "", NULL_KEY, "";);//resetting the channel
}
if (message == "Upper Circle";) // and etc. "Upper Circle" is the name of the prim you touched in the HUD.
:
:
_____________________
Flivelwitz Alsop
Registered User
Join date: 26 Mar 2008
Posts: 6
03-19-2009 03:43
Thanks for your help here, all. I will test them out!

Fliv