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

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

Recommended Posts

Posted (edited)

I have two versions of a script that hides mesh. 

1st version shows a dialogue on touch with 2 buttons - on /off.

2nd version is an updated version with a settings button that enables me to tell the script to work on touch for only the owner - me.

In both versions theres llOwnerSay function that should tell me who clicked the off button that hides the mesh - the problem is llOwnerSay returns blank in the 2nd version. It returns it like this in chat " Object:  took off your clothes"

I am not sure why the name is blank in the 2nd version, did I call the function wrong or wrote it completely wrong? Is the UUID of the toucher getting lost in the script due to the menus? The settings work as intended and let me only when clicked on the Owner Only button in dialogue.

Forgive me if I wrote something wrong or something that doesnt make sense, I tried to figure out if I can fix it while writing this thread.

1st script that returns the name sucessfully.

list buttons = ["On", "Off"];
string dialogInfo = "\nPlease make a choice.";
 
key ToucherID;
integer dialogChannel;
integer listenHandle;

remove_listen_handle()
{
    llListenRemove(listenHandle);
}
 
default
{
    state_entry()
    {
        dialogChannel = -1 - (integer)("0x" + llGetSubString( (string)llGetKey(), -7, -1) );
    }
 
    touch_start(integer num_detected)
    {
        ToucherID = llDetectedKey(0);

        listenHandle = llListen(dialogChannel, "", ToucherID, "");
        llDialog(ToucherID, dialogInfo, buttons, dialogChannel);
        llSetTimerEvent(10.0); 
    }
 
    listen(integer channel, string name, key id, string message)
    {
        string Input;
        Input = llKey2Name(ToucherID);
        if (message == "On")
        {
            llSetLinkAlpha(LINK_ALL_OTHERS, 1.0, ALL_SIDES);

           remove_listen_handle();
           
        }
 

 
        else if (message == "Off")
        {
            llSetLinkAlpha(LINK_ALL_OTHERS, 0.0, ALL_SIDES);

           llOwnerSay(Input + " took off your clothes");
           remove_listen_handle();
           
        }
       
        
    }
 
}

 

2nd version that returns blank name

list public = ["On", "Off", "Settings"];
list settings = ["Everyone", "Owner Only"];
string settingdialog = "S";
string Input;
integer lhandle;
integer dchannel = -254698458;
key owner;
key toucherid;

public_menu(key inputKey, string inputString, list inputList)
 
{
    toucherid = llDetectedKey(0);
    owner = llGetOwner();
        
    llDialog(toucherid, "Choose", public, dchannel);
}

setting_menu(key inputKey, string inputString, list inputList)
 
{
    toucherid = llDetectedKey(0);
    owner = llGetOwner();

    llDialog(owner, "Choose", settings, dchannel);
}


close_menu()

{
    llSetTimerEvent(0.0);
    llListenRemove(lhandle);
}


default
{
    state_entry()
        {
            state PUBLIC;
            lhandle = llListen(dchannel, "", toucherid, "");
        }
        
    changed(integer change)
        {
            if (change & CHANGED_INVENTORY)
        {
            llResetScript();  
        }
    }
}    

state PUBLIC
{
    touch_start(integer num_detected)
    {
        toucherid = llDetectedKey(0);
        lhandle = llListen(dchannel, "", toucherid, "");
        Input = llKey2Name(toucherid);

        public_menu(owner, settingdialog, public);
    }
    
    listen(integer channel, string name, key id, string message)
    
    {   
        toucherid = llDetectedKey(0);
        Input = llKey2Name(toucherid);
        owner = llGetOwner();
        

        if(message == "Settings" && id == owner)
        
        {
            setting_menu(toucherid, settingdialog, settings);
        }
            
        
         if(message == "Settings" && id != owner)
         
        {
            close_menu();                
        }
        
        if(message == "On")
        {
            llSetLinkAlpha(LINK_ALL_OTHERS, 1.0, ALL_SIDES);

           close_menu();
           
        }
        
         if (message == "Off")
        {

          
            llSetLinkAlpha(LINK_ALL_OTHERS, 0.0, ALL_SIDES);
            
           llOwnerSay((string)Input + " took off your clothes");

           close_menu();
        
        }
        
        
        else if(message == "Owner Only")
        
        {
            state OWNER;
            close_menu();
            
        }
        } 
}

state OWNER

{
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
    
    touch_start(integer num_detected)
    {
        lhandle = llListen(dchannel, "", "", "");
        toucherid = llDetectedKey(0);
        owner = llGetOwner();
        
        if(toucherid == owner)
        {
            public_menu(owner, settingdialog, public);
        }
        
         else if(toucherid != owner)
        {
            close_menu();
        }
        
        
        }
        
listen(integer channel, string name, key id, string message)
 {
     toucherid = llDetectedKey(0);
        owner = llGetOwner();
        if(message == "Settings")
        
        {
            setting_menu(owner, settingdialog, settings);
        }
        
        else if(message == "On")
        {
            llSetLinkAlpha(LINK_ALL_OTHERS, 1.0, ALL_SIDES);

           close_menu();
           
        }
        
         else if (message == "Off")
        {
            llSetLinkAlpha(LINK_ALL_OTHERS, 0.0, ALL_SIDES);
            close_menu();
        }
        
        else if(message == "Everyone")
        {
            state PUBLIC;
            close_menu();
        }
    }
}

 

Edited by Reiramon
Posted

The problem is here, in the listen event in both state PUBLIC and state OWNER ...

        toucherid = llDetectedKey(0);
        Input = llKey2Name(toucherid);

The llDetected* functions only work in touch_start, touch_end, collision_start, collision_end, and sensor events.  A listen event can't detect anything, so you can't use that function there. Fortunately, you already declared toucherid to be a global key variable, so the easy solution is to remove the line that says

toucherid = llDetectedKey(0);

from that one spot in the two listen events.  Its value is already captured and saved in the preceding touch_start event.

  • Like 1
  • Thanks 1
Posted

It's also worth noting that the listen event itself gives you the name and id of the avatar or object generating the message, listen (integer channel, string name, key id, string message), saving you having to dig them out for yourself.

 

  • Like 2
  • Thanks 1
Posted
27 minutes ago, Rolig Loon said:

The problem is here, in the listen event in both state PUBLIC and state OWNER ...


        toucherid = llDetectedKey(0);
        Input = llKey2Name(toucherid);

The llDetected* functions only work in touch_start, touch_end, collision_start, collision_end, and sensor events.  A listen event can't detect anything, so you can't use that function there. Fortunately, you already declared toucherid to be a global key variable, so the easy solution is to remove the line that says


toucherid = llDetectedKey(0);

from that one spot in the two listen events.  Its value is already captured and saved in the preceding touch_start event.

Thanks Rolig, it's returning the name now. 

That's what I get for not completely reading the function wiki. 

Posted

Edit:

On 10/5/2020 at 4:20 AM, KT Kingsley said:

It's also worth noting that the listen event itself gives you the name and id of the avatar or object generating the message, listen (integer channel, string name, key id, string message), saving you having to dig them out for yourself.

 

Well I tried what KT Kingsley said and it works too. Is it better to script with the key toucherID or just handle the listen event to find the ID of avatar? Follow up: I need to declare llDetectedKey(0) in llDialog in touch_start anyway right? Because when I leave it blank (llDialog("", dInfo, buttons, dChannel);) the dialog wont show.

integer dChannel = 0;
integer lHandle;
string dInfo = "Info";
list buttons = ["Button"];
key toucherID;

default
{
    state_entry()
    {

    }

    touch_start(integer num_detected)
    {
        lHandle = llListen(dChannel, "", "", "");
        toucherID = llDetectedKey(0);
        llDialog(toucherID, dInfo, buttons, dChannel);
    }

    listen(integer channel, string name, key id, string message)
    {
        string input = llGetDisplayName(id);
        
        if (message == "Button")
    
        llSay(0, (string)input + " Touched me");
     
}
}

 

Posted

I suggested that the easiest solution was to just remove that line from the listen event because it just meant hitting the delete key twice, since you already had toucherID saved as  a global key variable.  It was an expedient solution.  KT's solution is actually the better one. It's what we both would have done if we had been writing the script from scratch.  After all, as he said, the name and UUID of the sender are always provided automatically whenever your script captures a message.  That's what the name and id parameters  in that event are.

Anyway, yes, you still need to grab the UUID with llDetectedKey in the touch_start event, because it is used there.  You don't need to pass it to the listen event unless you really want to.

  • Like 1
You are about to reply to a thread that has been inactive for 1520 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...