Jump to content
You are about to reply to a thread that has been inactive for 765 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Posted

I have been testing my HUD and noticed it wont listen to HUD commands if the object is touched by another avatar when rezzed. (rez object - > touch the start listen button on different avi -> object wont listen). Only resetting the script manually makes it work again.

The  "llOwnerSay("HUD activated. The listener will remain active for 3 minutes.");" still works on button touch but it looks like the object isnt getting any command from the HUD. 

Any idea why?

Thanks!

 

integer dChannel;
integer lHandle;
key id;

remove_listen_handle()
{
    llListenRemove(lHandle);

}

default
{
    
    changed(integer change)
    {
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    
    on_rez(integer start_param)
    {
       llResetScript();
    }

    touch_start(integer total_number)
    {
        dChannel = ((integer)("0x"+llGetSubString((string)llGetOwnerKey(id),-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF;
        id = llDetectedKey(0);
        if (id == llGetOwner())
        {
        lHandle = llListen(dChannel, "", "", "");
        llOwnerSay("HUD activated. The listener will remain active for 3 minutes.");
        llSetTimerEvent(180.0);
    }
    
}
    listen(integer channel, string name, key id, string message)
..............

 timer()
        {
            remove_listen_handle();
            }
           } 
  

 

Posted (edited)

Firstly, what is the id variable initialized to? What do you expect it to be the first time anyone clicks on the object? Because it is not shown from the snipped you've posted. And if it's never actually set to anything first, then it will be NULL_KEY.

Secondly, the problem as I see it is that you're always updating dChannel and id when anyone clicks the object, even if they're not the owner. That will have repercussions for the next time the touch_start event is triggered. Consider this sequence:

  1. object freshly rezzed.
  2. person A clicks it (they are not the owner)
  3. in the touch_start event, dChannel is set to... something, we don't know, but ignore that for now.
  4. variable id is set to person A's key
  5. person A is not the owner , so the IF clause evaluates to false and nothing else happens.
  6. person B clicks the object (they are the owner)
  7. in the touch_start event, dChannel is set to some number based off of person A's key because id still holds that value from last time.
  8. variable id is set to person B's key
  9. person B is the owner so the IF clause evaluates to true and continues on
  10. llListen is called using dChannel - but remember, dChannel is based off of person A's key from the previous click. Is that what you wanted?

It's hard to say for sure without knowing more about your script, but since you only open the listen when the owner clicks, I'm assuming you only want dChannel to be based off of the owner's key. If that's accurate, then you should probably move the updating of dChannel into the same section of code where llListen is, within the IF clause.

Otherwise dChannel will always be based on the key of the previous person who clicked the object, and not the current person who clicked it (especially if they're also the owner).

Edited by Fenix Eldritch
Posted
7 minutes ago, Fenix Eldritch said:

Firstly, what is the id variable initialized to? What do you expect it to be the first time anyone clicks on the object? Because it is not shown from the snipped you've posted. And if it's never actually set to anything first, then it will be NULL_KEY.

Secondly, the problem as I see it is that you're always updating dChannel and id when anyone clicks the object, even if they're not the owner. That will have repercussions for the next time the touch_start event is triggered. Consider this sequence:

  1. object freshly rezzed.
  2. person A clicks it (they are not the owner)
  3. in the touch_start event, dChannel is set to... something, we don't know, but ignore that for now.
  4. variable id is set to person A's key
  5. person A is not the owner , so the IF clause evaluates to false and nothing else happens.
  6. person B clicks the object (they are the owner)
  7. in the touch_start event, dChannel is set to some number based off of person A's key because id still holds that value from last time.
  8. variable id is set to person B's key
  9. person B is the owner so the IF clause evaluates to true and continues on
  10. llListen is called using dChannel - but remember, dChannel is based off of person A's key from the previous click. Is that what you wanted?

It's hard to say for sure without knowing more about your script, but since you only open the listen when the owner clicks, I'm assuming you only want dChannel to be based off of the owner's key. If that's accurate, then you should probably move the updating of dChannel into the same section of code where llListen is, within the IF clause.

Otherwise dChannel will always be based on the key of the previous person who clicked the object, and not the current person who clicked it (especially if they're also the owner).

This script is in an object that is rezzed in world in link 4 that acts as a button to initialise listen to the HUD that an avatar wears (I went this route to close the listen handle, as seemingly, never ending listen has impact on SIM resources - dunno how big). This is the whole script minus the UUIDs for textures, normals, specular and other settings in the listen event. 

I intended to make the object listen only to the owner and their HUD. That's why I found this way of doing the channel. 

If I used a random channel like -8899 on all objects, I think the HUD would react to to different people's HUDs on the ame sim (no matter how small chance it is that 2 people will buy my object).

I'm a scripter beginner, so I found this channel on forums here with Google.

I think i changed it and used LlGetOwnerKey instead of LlGetKey which was in the original post.

 

The reasoning for this is, I thought that llGetKey won't work as the object and the HUD will have different keys and the HUD won't work.

The id variable should work in the touch start with the if statement, so if an owner touches it, it starts the listen event, if someone else touches it. It does nothing.

 

I tried changing it since posting this to include this under if(id == llGetOwner)

if(id != llGetOwner) 

{

//Do nothing

}

But that didn't work alone

What seemingly worked was: I changed 

dChannel = ((integer)("0x"+llGetSubString((string)llGetOwnerKey(id),-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF;

To

dChannel = ((integer)("0x"+llGetSubString((string)llGetOwner()),-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF;

This seemingly works, I can touch the button on a different avatar, and then touch the button as the object owner and the object now responds to the HUD.

Tried this on 3 different avis, clicking the button and it still worked and the object responded.

You are correct in what you said about what was happening in the sequence.

I assumed that 

id = llDetectedKey(0);

        if (id == llGetOwner())

        {

        lHandle = llListen(dChannel, "", "", "");

Will mean that the object will only start the listen if the toucher is the owner. if it's someone else it won't listen.

Likewise I assumed if I used llGetOwnerKey, the object won't use someone else's key, but only the owners.

As I said I'm very much of a scripting beginner. 

Is it OK to use it like that with llGetOwner instead of llGetOwnerKey in dChaannel?

I will try to move it within the if statement.

(I typed this on phone, sorry if there's bad formatting)

 

 

 

Posted (edited)
1 hour ago, arisaie said:

Is it OK to use it like that with llGetOwner instead of llGetOwnerKey in dChaannel?

llGetOwnerKey and llGetOwner both will return the key of the avatar who owns an object. The difference between them is that llGetOwnerKey can target any object rezzed in the region, and llGetOwner can only target the object that the script is currently residing within. If you're only concerned about the object that contains this script, then use llGetOwner.

A unique channel is definitely important when you're dealing with multiple instances of the same product. However you should also consider adding further parameters to the llListen filter if possible. For example, is the HUD's name expected to remain constant? If it doesn't change, you can add that to the llListen filter. This won't help with duplicate instances of your HUDs, but it will eliminate the rezzed object potentially hearing chat from other people's creations that might happen to use the same channel (you never know).

Another method of filtering out unwanted chat messages is by using llRegionSayTo. This allows the scripted object to talk directly to the target object, and you can be assured that only that target will ever hear that (assuming it still fulfills the llListen filter criteria). Using that function in your HUD to talk to the rezzed object might be worth looking into.

Lastly, I would highly recommend you spend some time reading up on the various LSL functions in the wiki. That is where everything is documented and where you can learn how these functions are used, as well as see examples.

https://wiki.secondlife.com/wiki/LSL_Portal

The wiki also has introduction tutorials that can be helpful for those new to scripting, or programming in general.

https://wiki.secondlife.com/wiki/LSL_Tutorial

Edited by Fenix Eldritch
  • Like 1
You are about to reply to a thread that has been inactive for 765 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...