Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Detaching or minimize a HUD item via click?

Serenity Galli
Registered User
Join date: 25 Dec 2007
Posts: 15
04-22-2008 06:12
I have made a HUD and all is working fine. However, I would like to click an X spot to detach it from the HUD. I have not figured out a good way to minimize a HUD other than having a narrow and long HUD and rotating it to another side making it appear smaller, but with a square style HUD that I have it seems the best to make it simple for people to detach it.

I have unsuccessfully tried llDetachFromAvatar() and llDie(). llDie() does not work when attached and the description of llDetachFromAvatar() leaves a lot to be desired (something about needing permissions?).

Any help would be appreciated
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-22-2008 06:53
Here is a small example for a two button HUD. The permissions thing isn't as bad as it might look at first, it is silently granted for items already worn.

CODE


default
{
touch_start(integer touched)
{
integer primnum = llDetectedLinkNumber(0);
if (primnum == LINK_ROOT) {
llOwnerSay("You pressed the main button.");
}
else if (llGetLinkName(primnum) == "detach") {
llOwnerSay("You pressed the detach button.");
llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);
}
}

run_time_permissions(integer perms) {
if (perms & PERMISSION_ATTACH) {
llDetachFromAvatar();
}
}
}

_____________________
Chatlan Mapholisto
Registered User
Join date: 7 Dec 2007
Posts: 7
04-22-2008 07:24
Here is another choice. If code is already long and need more memory, check this.

*** script example for the root prim ***
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();
}
}
}
}

*** script example for the "X" prim ***
default
{
touch_start(integer num_detected)
{
llMessageLinked(LINK_ROOT, 0, "detatch", NULL_KEY);
}
}

**************************************************
1) llDetachFromAvatar()
llDetachFromAvatar() needs PERMISSION_ATTACH to work.
This function will not work in a child prim.

2) llDie()
llDie() has no effect if called from within an attachment.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-22-2008 08:08
You can do all that with just one script in the root prim, llDetectedLinkNumber tells you what prim was touched. It's good for lag reduction to keep the script count down, if you don't need the extra memory or have things that simply can't coexist in a single script.
_____________________
Chatlan Mapholisto
Registered User
Join date: 7 Dec 2007
Posts: 7
04-22-2008 10:39
Thank you Viktoria for your suggestion, and sorry for my laggy one.
I also think using touch_start in the root prim is a good way.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
04-22-2008 11:21
Not much of a worry if you only have 2 or 3 prims, but it adds up when HUDs morph into 50-button monsters =) The Mono playgrounds are always busy running stuff, so it's really hard to tell if this kind of thing will matter as much going forward. Memory management will be better, so there will be at least some difference.
_____________________
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
04-22-2008 11:44
From: Viktoria Dovgal
Memory management will be better, so there will be at least some difference.

Really looking forward to that, I have vendors which ended up having two scripts each because the main script only had 300 bytes left at the end! Bah, I have a whole other script to give me an extra 1k of memory (rarely need to cache more than that) =(
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Chatlan Mapholisto
Registered User
Join date: 7 Dec 2007
Posts: 7
04-22-2008 13:17
From: Viktoria Dovgal
Not much of a worry if you only have 2 or 3 prims, but it adds up when HUDs morph into 50-button monsters =)


I've not tested Mono yet.. but I also feel memory management is important. Short and simple code is nice and beautifle and I want to improve my skills of writing scripts and human language.
Thank you Viktoria.

P.S. I think about deleting my old post but I'll leave it as a bad sample.