Jump to content

Detaching a HUD


Omega Tunwarm
 Share

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

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

Recommended Posts

Hello, I made a HUD, and I found a script for detaching it:

1. This is the X prim script (and it works just fine)

default
{
touch_start(integer num_detected)
{
llMessageLinked(LINK_ROOT, 0, "detatch", NULL_KEY);
}
}

2. This is the root prim script, but I encounter an error on it:  (4, 29) : ERROR : Name not defined within scope

default
{
on_rez(integer start_param)
{
llRequestPermissions(attached, PERMISSION_ATTACH);
}

link_message(integer sender_num, integer num, string str, key id)
{
if ("detatch" == str)
{
//if (PERMISSION_ATTACH & llGetPermissions())
{
llDetachFromAvatar();
}
}
}
}

Does anyone know what's not correct? 

Edited by Omega Tunwarm
Link to comment
Share on other sites

Use...

llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);

The function llRequestPermissions() requires the key of an avatar and the permissions being requested. In the case of a HUD the avatar wearing it is always its owner, so llGetOwner() will return the key of the avatar wearing the HUD. The name "attached", in your script, has not been defined so it's causing the error you see.

  • Thanks 1
Link to comment
Share on other sites

Assuming the HUD is going to be attached by users, from their inventory, and the only time you want to do anything with attachment permissions is when you come to detach it, I wouldn't bother with checking on permissions in the link_message event.

It's just as simple to ask for PERMISSION_ATTACH when you need it -- when the HUD is to detach from the avatar -- and not before.   Indeed, it simplifies the logic if the only time the script asks for PERMISSION_ATTACH is when it wants to detach the HUD.

So something like

key kOwner;
string strTrigger = "detach";//I like to use variables for as much as possible so I can copy/paste them between scripts so as to avoid typos
default
{
	state_entry(){
		kOwner = llGetOwner();
	}

	attach(key id){
		if(id){
			kOwner = id;
		}
	}

	link_message(integer sender_number, integer number, string message, key id){
		if(strTrigger == message && (llGetAttached())){//no point in trying to detach something that's not attached in the first place
			llRequestPermissions(kOwner,PERMISSION_ATTACH);
		}
	}

	run_time_permissions(integer permissions){
		if(permissions & PERMISSION_ATTACH){
			if (llGetAttached()){
				llDetachFromAvatar();
			}
		}
	}

}

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

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