Jump to content

Sending a command on detach


agentronin
 Share

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

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

Recommended Posts

default
{
  attach(key AvatarKey)
  {   if (AvatarKey)
      {  llSay(15,"toenails off");
         llOwnerSay("toenails off");
      }  else  if ((llGetAttached() == 0)
      {  llSay(15,"toenails on");
         llOwnerSay("toenails on");
      }
  }
}

The above code is intended to turn off toenails on a Slink Physique Redux BOM body when the prim it is in is attached, and on again when detached. It is needed because the alpha layer, that is needed when shoes are attached, does make the feet disappear but not the toenails.

This code is inserted in a prim that is attached to the avatar when shoes are attached, and is detached when the shoes are detached.

The two llOwnerSay() calls are there for debugging. The script does turn off the toenails when attached. But it fails to turn them on when detached. I know the llSay(15,"toenails on") statement gets executed upon detachment because I get the "toenails on" text in local chat.

I know the command to turn them on is the correct one because typing "/15 toenails on" in Firestorm's "Nearby Chat" does work to turn on the toenails.

Why does this code fail to turn on toenails?

Edited by agentronin
Link to comment
Share on other sites

May I suggest the following modification?

default
{
    attach(key AvatarKey)
    {
        if (!AvatarKey)  // if AvatarKey evaluates as FALSE...
        {
            llSay(15,"toenails on");    
            llOwnerSay("toenails on");
        } 
        else
        {
            llSay(15,"toenails off");
            llOwnerSay("toenails off");
        }
    }
}

This way the script first checks for the absence of the AvatarKey, this saves a little time and may be enough to trigger the nails being hidden.

No guarantees though, but it COULD work.

Link to comment
Share on other sites

I have a few things that work in the same way, and they do work pretty well. I've found you can get a couple of lines of code to execute pretty reliably in the attach even when the object is being detached. I suspect the occasional failure is due to to a very busy simulator. Any code not executed when the object is detached does pick up where it left off when the object is reattached.

My code looks like this: 

    attach (key id)
    {
        if (id) //object has been attached
        {
            //do stuff when attached
        }
        else //object is being detached
        {
            //do stuff when detached
        }
    }

 

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

According to:
http://wiki.secondlife.com/wiki/Attach
The code:

llGetAttached() == 0

is necessary as explained in that wiki's first caveat.

That the message "toenails on" appears in Firestorm's Nearby Chat shows the script had to have enough to time to get to the point of executing:

llSay(15,"toenails on")

because the line that sent the "toenails on" message to Nearby Chat is executed after this.

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, agentronin said:

According to:
http://wiki.secondlife.com/wiki/Attach
The code:


llGetAttached() == 0

is necessary as explained in that wiki's first caveat.

That the message "toenails on" appears in Firestorm's Nearby Chat shows the script had to have enough to time to get to the point of executing:

llSay(15,"toenails on")

because the line that sent the "toenails on" message to Nearby Chat is executed after this.

I'd never looked at the caveats for the attach event before this! That's useful to know. Also, I found an explanation for something that's been bugging me for ages in there too. Thanks for pointing this out.

Maybe the issue you're having is something to do with something like the Slink script checking keys or owner keys or the attachment status of the source of the command that get messed up during a detach?

In my amateurish hacky way, I guess I'd try using a second attached object (maybe a permanently worn HUD) that gets a message from the first object when it's detached, and then issues the toenail command itself, perhaps detaching itself after that. Or something like that.

Link to comment
Share on other sites

6 hours ago, agentronin said:

According to:
http://wiki.secondlife.com/wiki/Attach
The code:



llGetAttached() == 0

is necessary as explained in that wiki's first caveat.

That the message "toenails on" appears in Firestorm's Nearby Chat shows the script had to have enough to time to get to the point of executing:

llSay(15,"toenails on")

because the line that sent the "toenails on" message to Nearby Chat is executed after this.

While the caveat is true, your script is so simple that having that check is unnecessary. There are no adverse effects if, for example, the detach event doesn't start until the object is reattached again. In that situation, the first attach event would show the toenails, and the second attach event would immediately hide them again.

As to what the problem is, Lucia had it right.

  • The message is sent during detach.
  • The sending object disappears.
  • The receiving object gets a listen event.
  • The receiving object checks: llGetOwnerkey(id) == llGetOwner()

I don't think this is something you can fix without access to the body's scripts.

Edited by Wulfie Reanimator
Link to comment
Share on other sites

I have solved this problem. Instead turning toenails on upon detach, I had to have the script RLV attach a prim with a script that turns the toenails on. So now there is a system of two scripts. Here are the two scripts:

Quote

// Slink Toenails Hide
//
// Written by:
// Agent Ronin (agentronin)
// secondlife:///app/agent/28e3faba-fcac-458a-8dab-b00145b057cf/about
// February 8, 2021
//
// This script turns off the toenails on a Slink Physique Redux
// avatar when the prim this script is in is attached. When its prim
// is detached this script attaches all in the folder:
//
// #RLV/.Slink Toennails Show
//
// This folder must contain a prim with script in it that turns the toenails on, and
// then detaches its prim.
//
// RLV must be enabled in the user's viewer to be able to attach that folder.
//
// The script "Slink Toennails Show" is the companion script meant to work with
// this "Slink Toennails Hide" script, and should be in a prim, and in the
// folder above.
//
// This "Slink Toenails Hide" script, and its companion "Slink Toennails Show" is
// necessary because alpha layers do not hide toenails. These scripts should be used
// wherever an alpha layer is required to hide the toes.
//
// In cases where the feet clip through shoes, and so must be hidden by
// alpha layer, this "Slink Toenails Hide" script, and its companion
// "Slink Toenails Show" script counterpart, make possible toenails looking right after RLV
// stripping shoes, or boots, without the user having to do anything to turn the toenails on.
//
// References:
//    http://wiki.secondlife.com/wiki/Attach
//    http://wiki.secondlife.com/wiki/LSL_Protocol/RestrainedLoveAPI#Inventory.2C_Editing_and_Rezzing

default {
  attach(key AvatarKey)
  {
    if (AvatarKey)
    { llSay(15,"toenails off");
    }else //if( llGetAttached() == 0 ) // This attached check turned out to be unnecessary.
    {
       // The below commented out section does not work. So it had to be
       // done by means of RLV.
       // Reference: https://community.secondlife.com/forums/topic/467818-sending-a-command-on-detach/
       /*
       llSay(15,"toenails on");
       llOwnerSay( "toenails on" );
       */
       
       // Attach the script that will make the toenails show.
       // Note that the folder path begins with a "." charadter.
       // This hides the folder from a collar's menu system.
       llOwnerSay( "@attachover:.Slink Toenails Show=force" );
    }
  }
 
  // Minimize reserved memory for ths script. Needed for security orbs
  // that control for resource usage.
  state_entry()
      {
          integer i;
           while( i++ < 10 && !llSetMemoryLimit( llGetUsedMemory() + 500 ))
        {
        }
  }
}

 

Quote

// Slink Toenails Show
//
// Written by:
// Agent Ronin (agentronin)
// secondlife:///app/agent/28e3faba-fcac-458a-8dab-b00145b057cf/about
// February 8, 2021
//
// This is the counterpart script to the "Slink Toenails Hide" script.
// This script must be put in its own prim, and must be on the #RLV
// folder path that is pointed to in the "Slink Toenails Hide"
// script.
//
// See the comments in the "Slink Toenails Show" script for details.
//

default {
  attach(key AvatarKey) {
    if (AvatarKey) {
      llSay(15,"toenails on");
      llRequestPermissions(AvatarKey, PERMISSION_ATTACH );
    }
  }
 
  run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_ATTACH)
        {  
            llSleep(3.0);
            llDetachFromAvatar( );
        }
    }
}

 

Link to comment
Share on other sites

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