Go Back   Second Citizen MK II > The Mainland: Second Life® > Content Creation > Scripting Tips

Reply
 
Thread Tools Display Modes

Scripting help (hud + attachment)
Old 01-26-2010, 08:55 AM   #1
jackalennui
>o< spider power!

jackalennui's Avatar
 
Join Date: Sep 2009
Posts: 315
My Mood:
Default Scripting help (hud + attachment)

I could use a bit of scripting help here .. I have a hud which whispers instructions on some channel, and an attachment listening and doing stuff. What I want it the attachment only "hearing" stuff when the HUD and itself belong to the same owner, otherwise one person with the hud could - possibly - influence another person's attachment if they are standing close together. I tried having it listen to owner only but obviously that doesn't work since the HUD is not the avatar, and filtering by object name won't work either since every HUD is called the same. Hm.. best I can come up with is the HUD renaming itself to "Avatar Name's HUD" and the attachment listening for whispers from "Avatar Name's HUD".

So, any hints? Pretty please?
jackalennui is offline   Reply With Quote

Old 01-26-2010, 11:14 AM   #2
Cale Vinson
Senior Member

Cale Vinson's Avatar
 
Join Date: Aug 2009
Posts: 1,925
Awards Showcase
28th 
Total Awards: 1
Default

Warning: I'm semi-retired form LSL nowadays, so take what follows with a grain (or boulder ) of salt.

If memory serves, the attachment will get the key of the Hud when the attachment listen-event fires:

listen(integer channel, string name, key id, string message)

The attachment knows who its owner is via "llGetOwner()". The attachment can also find out who the owner of the Hud is via "llGetOwnerKey(id)" in the listen-event-handler code. If these two aren't the same, then you know not to respond to the whisper.

I think.

Shouldn't be too hard to try at least, just a line or two of script.
Cale Vinson is offline   Reply With Quote
This user agrees. But then, who wouldn't, right?

Old 01-26-2010, 11:24 AM   #3
Cale Vinson
Senior Member

Cale Vinson's Avatar
 
Join Date: Aug 2009
Posts: 1,925
Awards Showcase
28th 
Total Awards: 1
Default

Dug back through my code to find an example, found this (from March 2007 - yikes, how time flies!).

The listen-event-handler. Its mostly fluff as far as your concerned, but the key bit is the "id" parameter, which is passed down to the routine that actually does the work in this particular example, "ListenHandlerChildObjects".

Code:
    listen(integer channel, string name, key id, string message)
    {
        list msgAsList;
        integer msgLen;
        
        msgAsList = llParseString2List(message, ["::"], []);
        msgLen = llGetListLength(msgAsList);
        
        if ( channel == gChannelChild )
            ListenHandlerChildObjects(name, id, msgAsList, msgLen);
    }
"ListenHandlerChildObjects" then uses the function calls outlined above to "early-out" if the owners of the speaker and listener aren't the same:

Code:
ListenHandlerChildObjects(string name, key id, list msgAsList, integer msgLen)
{
    string cmd;
    integer objCount;
    
    if ( llGetOwner() != llGetOwnerKey(id) )
        return;
    
    ....
    ....
Cale Vinson is offline   Reply With Quote
This user agrees. But then, who wouldn't, right?

Old 01-26-2010, 01:32 PM   #4
jackalennui
>o< spider power!

jackalennui's Avatar
 
Join Date: Sep 2009
Posts: 315
My Mood:
Default

Quote:
Originally Posted by Cale Vinson View Post
Warning: I'm semi-retired form LSL nowadays, so take what follows with a grain (or boulder ) of salt.

If memory serves, the attachment will get the key of the Hud when the attachment listen-event fires:

listen(integer channel, string name, key id, string message)

The attachment knows who its owner is via "llGetOwner()". The attachment can also find out who the owner of the Hud is via "llGetOwnerKey(id)" in the listen-event-handler code. If these two aren't the same, then you know not to respond to the whisper.

I think.

Shouldn't be too hard to try at least, just a line or two of script.
Thank you! That's exactly what I was looking for.
jackalennui is offline   Reply With Quote

Old 02-02-2010, 01:17 PM   #5
Innula Zenovka
Has a crush on Unregistered

Innula Zenovka's Avatar
 
Join Date: Feb 2010
Posts: 13
Default

No need to tell it what to do if the message isn't from something belonging to the owner (or from the owner -- if id in llGetOwnerKey(id) is that of an avatar it returns the same key)
Code:
listen(integer channel, string name, key id, string msg) {
	if (llGetOwnerKey(id)==llGetOwner()){
	
	// do stuff
	}
}
does the trick.
Innula Zenovka is offline   Reply With Quote
This user agrees. But then, who wouldn't, right?
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -4. The time now is 04:02 AM.


vBulletin skins developed by: eXtremepixels
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Second Life® and Linden Lab® are trademarks of Linden Research, Inc.
Second Citizen MK II Forums are not affiliated with or sponsored by Linden Research.
© 2009 - 2011 Second Citizen MKII [SC MKII]
| Home | Register | FAQ | Members List | Calendar | Today's Posts | Search | New Posts |