Jump to content

Grab UUID of the person 'touching' the object


satyajitdas20
 Share

You are about to reply to a thread that has been inactive for 298 days.

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

Recommended Posts

Hello again,

I am using a Growl enabled script (used for Growl and Prowl clients using API) which does this.

When i click on the Object with the script, a dialogue box opens and a message of upto 100 characters can be written and submitted. I receive an almost immediate notification with the complete message on my Prowl Client in my iPhone. This is good.

But the problem here is:

When i place the Object at my land and someone else clicks on it to send me a message, the dialog box doesnot open for them. It rather opens for me. (It doesnt matter if i am in the same region, or somewhere else). What i could figure out till now is that the script should be such that it should grab the UUID of the person clicking it and the message should be sent to the UUID of the person who is the owner of the Object. I understand there is something that needs to be changed at llGetOwner() but i am not able to figure out what needs to be changed and how.

Here is the script:

integer comChannel = 0;
 
default
{
    
    
    touch_start(integer total_number) {
        comChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        llListen(comChannel, "", llGetOwner(), "");
        llTextBox(llGetOwner(), "\nPlease enter a test-string to broadcast to growl-enabled devices:\n", comChannel);
    }
    listen(integer channel, string name, key id, string message) {
        llMessageLinked(LINK_THIS, comChannel, message, id);
    }
}

Edited by satyajitdas20
Link to comment
Share on other sites

57 minutes ago, satyajitdas20 said:

the script should be such that it should grab the UUID of the person clicking it and the message should be sent to the UUID of the person who is the owner of the Object.

Correct. Both llTextBox and llListen take a UUID as one of their parameters and that it how those functions select their target to send the textbox to or listen to respectively.

For those functions you could simply replace llGetOwner with llDetectedKey(0) which represents the UUID if the person who just triggered the touch event. The detected functions only work in a select few events like touch_start, but they are exactly for this kind of purpose.

Note that in this case, the commChannel can continue to use the integer generated from the owner's key, as it's just used for internal communications with the link message. Heck, you could probably remove the line that updates it in the touch_start event and just give it a random number when you declare it. Just make sure you use the same number in the other scripts.

You should however close your listen handler in the listen event so that you don't amass an ever increasing collection of listens as more and more people click the object. See llListenRemove.

Edited by Fenix Eldritch
correction
  • Like 1
Link to comment
Share on other sites

  • satyajitdas20 changed the title to Grab UUID of the person 'touching' the object
3 hours ago, Fenix Eldritch said:

close your listen handler in the listen event

That would probably work well enough in practice, but you'll accumulate an 'orphaned' listen handle every time someone doesn't respond to the textbox. The 'standard' approach is to remove the listen on a timer, and before adding a new one with the same function.

integer comChannel = 0;
integer comHandle;
default
{
    touch_start(integer total_number) {
        llListenRemove(comHandle);
        comChannel = (integer)llFrand(1000000000)-1000000000;
        llSetTimerEvent(120.0); // 2 minute allowance for response.
        comHandle = llListen(comChannel, "", llDetectedKey(0), "");
        llTextBox(llDetectedKey(0), "\nPlease enter a test-string to broadcast to growl-enabled devices:\n", comChannel);
    }
    listen(integer channel, string name, key id, string message) {
        llMessageLinked(LINK_THIS, comChannel, message, id);
        llListenRemove(comHandle); // come to think of it though, you do need to remove it in the listen event as well to prevent double responses.
        llSetTimerEvent(0);
    }
    timer()
    {   llSetTimerEvent(0);
        llListenRemove(comHandle);
    }
} 

although, personally I generally prefer a fixed channel and llListenControl();

integer comChannel = -14523;
integer comHandle;
default
{
    state_entry()
    {   comHandle = llListen(comChannel,"","","");
        llListenControl(comHandle,FALSE);
    }
    touch_start(integer total_number) {
        llListenControl(comHandle,TRUE);
        llSetTimerEvent(120.0); // 2 minute allowance for response.
        llTextBox(llDetectedKey(0), "\nPlease enter a test-string to broadcast to growl-enabled devices:\n", comChannel);
    }
    listen(integer channel, string name, key id, string message) {
        llMessageLinked(LINK_THIS, comChannel, message, id);
        llListenControl(comHandle,FALSE);
        llSetTimerEvent(0);
    }
    timer()
    {   llSetTimerEvent(0);
        llListenControl(comHandle,FALSE);
    }
} 

 

Edited by Quistess Alpha
  • Like 2
Link to comment
Share on other sites

Sweet scripting, QA. Anyway for the op,

  llTextBox(llGetOwner() is why your getting the box - you're the owner. llTextBox(llDetectedKey(0) will pick up the first avatar to click it. 

Also I like randomising the channel number of the listener using one of these plagarised code lines so the ch number becomes unique to the owner...

integer MySecretChannel = (integer)("0xF" + llGetSubString(llGetOwner(),0,6));
--------------------
integer channel() 
{     return (integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1))*-1;   }

 

Edited by rasterscan
  • Like 1
Link to comment
Share on other sites

@Fenix Eldritch 

@Quistess Alpha

 Ok, so i was able to do this, and it works fine.

integer comChannel = 0;
integer comHandle;
default
{
    
    
    touch_start(integer total_number) {
        llListenRemove(comHandle);
        comChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        llSetTimerEvent(120.0); // 2 minute allowance for response.
        comHandle = llListen(comChannel, "", llDetectedKey(0), "");
        llTextBox(llDetectedKey(0), "\nPlease enter a test-string to broadcast to growl-enabled devices:\n", comChannel);
    }
    listen(integer channel, string name, key id, string message) {
        llMessageLinked(LINK_THIS, comChannel, message, id);
    llListenRemove(comHandle); // come to think of it though, you do need to remove it in the listen event as well to prevent double responses.
        llSetTimerEvent(0);
    }
    timer()
    {   llSetTimerEvent(0);
        llListenRemove(comHandle);
    }
}

@Quistess Alpha I tried the second code with 

integer comChannel = -14523;

However, it seems my other script dont recognize it anymore. And how do i setup the other code at the same channel, this is confusing me.

This is the second code:

string PROWL_API_KEY = "6e4533e1370953e10e72d3b818b5d5dd0646475c";
string PROWL_APPLICATION = "Prowler";
string PROWL_EVENT = "Tickled!";
 
//////////////////////////////////////////////////////////
//                      INTERNALS                       //
//////////////////////////////////////////////////////////
 
default
{
    link_message(integer sender_num, integer num, string str, key id) {
        integer cha = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        if(num != cha) return;
        string sLoad = "apikey=" + llEscapeURL(PROWL_API_KEY) + 
                        "&" + "application=" + llEscapeURL(PROWL_APPLICATION) +
                        "&" + "event=" + llEscapeURL(PROWL_EVENT) + 
                        "&" + "description=" + llEscapeURL(str);
        llHTTPRequest("https://api.prowlapp.com/publicapi/add", 
                        [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], 
                        sLoad);
    }
    on_rez(integer num) {
        llResetScript();
    }
}

 

Link to comment
Share on other sites

16 hours ago, satyajitdas20 said:

However, it seems my other script dont recognize it anymore. And how do i setup the other code at the same channel, this is confusing me.

This relates to my earlier post when I pointed out that you need to make sure both scripts use the same number. This is because I noticed you were sending comChannel as one of the parameters in llMessageLinked. Since llMessageLinked doesn't use channels like llListen, I assumed you were using it as some kind of verification to the other scripts - and in posting you second script, it looks like I guessed correctly.

Here's what's going on:

Originally, both scripts independently used the same formula to calculate the same unique number:

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

Your first script puts this value into the comChannel variable and your second script puts it in the cha variable. When your first script issues the linked message, it sends comChannel as the second input parameter. Over in your second script, that materializes as the value of the num variable in the link_message event.

So when your second script hears the link message, the first thing it does is use that same big formula to calculate the unique number. It then checks if that number (cha) is equal to the number passed to it from the link message (num). If they're not equal, then the script executes the return function and ends the event, effectively rejecting the link message.

Previously this worked fine when both scripts used the same method (formula) to generate the unique number (both scripts have the same owner so the result will be identical). But once you hard-coded one script to use a specific value (-14523), the other needs to do the same otherwise you'll never get a match.

In short, with the way you've written these scripts, comChannel in the first script and cha in the second script need to be assigned the same value. Doesn't matter if it's by using the same formula, or the same number, they just have to match.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 298 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
 Share

×
×
  • Create New...