This is going to be a long one. Get yourself a cup of coffee first.
What is a HUD? If you have to ask that question, you probably won’t get much from this article, but HUD is an acronym of Head-Up Display, and allows creators in Second Life to add a user-interface to gadgets.
They are created from prims just like any other user-created objects in Second Life, but they are only visible to their owner, and always appear ‘flat’ against the screen. If you’ve used any gadgets in Second Life, you will almost certainly have come across them.
For example, here is the popular blogHUD, for making blog postings from within Second Life:
When I started trying to create HUDs myself, I found that there was very little information about how to go about it, and I struggled for a while with even the simplest things. Now that I think I know what I am doing(!), I thought I would post a blog passing on my hard-won information!
In this post, I’ll show the basic steps of creating a HUD, and point out some of the pitfalls and ‘gotchas’ that you are likely to encounter along the way.
Are you sitting comfortably? Then I’ll begin…
The first thing to do, of course, is to decide what our HUD will contain. Because of the limitations of SL, it is not easy to include any kind of output in the HUD (with some ingenuity it can be done, but that is beyond the scope of this blog), so our HUD will basically be restricted to having some buttons to push.
For the sake of an example, we are going to create a HUD which allows the user to scan the area for other avatars, and to ‘poke’ (via chat) one of those avatars. Not very exciting, I know, but it is only an example!
We will need two buttons: Scan and Poke. We will also need some sort of ‘window’ for them to sit on. We could have them just floating on the screen, but that would look rather odd.
The first step is to create a sort of ‘rough draft’ of our HUD. I’ll explain why in a minute.
Let’s start with the window.
(Oh, one quick point – I am going to assume that you are fully familiar with creating/scaling/texturing prims. If you aren’t, you really shouldn’t be trying to create HUDs yet!).
Create a simple cube. Set the X scale to 0.01, so that you end up with a thin, flat board. Move it to somewhere close so that you can see it easily. If you want, you can blank the texture, though that isn’t important – we’ll deal with the texture later.
Next, let’s add a couple of buttons. Create two more cubes, setting the X scale to 0.1 again, and setting the Y and Z scale to something that approximates a sort of rectangular button shape. Place them flat against the ‘window’ board. Don’t worry about positioning them exactly yet, but you might want to colour them so that you can see them more clearly.
Link the buttons and the window (I’d suggest making the window the root prim, by selecting it last before linking, though it isn’t important for the simple HUD that we are going to make). One warning – don’t rotate this object, otherwise when you come to attach it, it might not be facing you!
Ok, now we have a primitive-looking window and buttons. Time to turn them into an actual HUD. Right-click the linked object, click ‘More’ on the pie menu, then click Attach HUD, and select Center.
If by chance you find that it is at the wrong angle (probably sideways!), you can rotate it even though it is attached. You might find it easier to adjust the numbers manually in the build dialog, rather than trying to use the Rotate tool.
Yuk. You now have a grotesque HUD, probably occupying far too much of the screen, and obscuring your view. Don’t worry, there are things we can do about it. In fact, if you are at all familiar with building stuff, I’m sure that you are already ahead of me. Hold fire, though, because there are a few things you need to know before going on.
Firstly, yes, you can edit the HUD when it is attached. This is very convenient, because an unattached HUD is very small and fiddly to work with. However, there are some limitations on what you can actually edit once the HUD is attached. This is why it is useful to do a ‘rough draft’ while the HUD is unattached and you have all the editing facilities available to you.
The most important limitation on editing an attached HUD is that you cannot unlink the prims that make up the HUD, and you cannot link new prims to the HUD. If you find that you need to add a new prim, you will have to detach the HUD (it will vanish into your inventory, and you will need to re-rez it, which is rather annoying), create and link the new prim, then re-attach the HUD.
To work on the individual elements of the HUD, you need to tick the ‘Edit linked parts’ checkbox on the Build dialog. I’ve found that this normally lets you do most things to the individual parts, although rescaling prims sometimes refuses to ‘take’. If you get that happening to you, unfortunately all you can do is drop the HUD and unlink it while you edit the offending prim.
For our simple example, rescale the entire HUD to something more suitable. You can then edit the two buttons to position them more exactly (this is much easier to do now that the HUD is attached).
Of course, it is still obscuring our view. For now, select the ‘window’ prim, blank the texture, colour it grey (or whatever you prefer), and set the transparency to something between 50 and 75.
You could do something similar with the buttons, but we need to get text onto these in some way. Because SL doesn’t yet provide text-on-a-prim, you will have to break out your favourite graphics program, and create some button textures.
Naturally, you can do something similar with the texture for your window prim, and create something fancier than the plain version that we’ve just made.
If you are feeling lazy, here are a couple of example button textures that you can use instead:
“Scan” button texture (.tga)
“Poke” button texture (.tga)
Here is the final result (I’ve done some resizing, and reattached the HUD at the top-left instead of the centre):
One final ‘gotcha’. Go back to when we originally attached the HUD, and we found that it took up large amounts of screen space. How much screen space do you imagine a prim of a given size will take up? The answer is…it depends. Most crucially, it depends on the size of the window (or the screen resolution if running full-screen) that Second Life is using. A HUD will occupy more space in a smaller window, less space in a larger window. You need to think about this when designing your hud (make the mistake of trying to create a ‘full-screen’ HUD, and it will only fit properly at one specific screen-size. Not good).
Ok, we now have our HUD designed and built…but it doesn’t actually do anything! Time to rectify that.
Select the buttons individually, and create a new script in each one.
For the Scan button, edit the script, and replace the default with the following, which does a simple scan of the surround area, and outputs the names of any avatars found (the output is done via llOwnerSay, so it is only visible to the user of the HUD):
default { touch_start(integer total_number) { llOwnerSay("Scanning..."); // Look for any avatars within 96m. llSensor("", NULL_KEY, AGENT, 96.0, PI); } sensor(integer num_detected) { integer i; while(i < num_detected) { if (llDetectedKey(i) != llGetOwner()) { llOwnerSay(llDetectedName(i)); } ++i; } } }
For the Poke button, replace the default script with this rather more elaborate one. This again does a scan of avatars in the vicinity, and then displays a dialog with their names as the buttons. When you select an avatar from the dialog, the chat message ‘[Your name] pokes [avatar name]’ is displayed.
integer dlgHandle = -1; integer dlgChannel = -9999; list avatarList = []; reset() { llSetTimerEvent(0.0); llListenRemove(dlgHandle); dlgHandle = -1; } default { touch_start(integer total_number) { llOwnerSay("Scanning..."); avatarList = []; // Look for any avatars within 10m. llSensor("", NULL_KEY, AGENT, 96.0, PI); } sensor(integer num_detected) { integer i; while((i < num_detected) && (i < 9)) { if (llDetectedKey(i) != llGetOwner()) { avatarList += [llDetectedName(i)]; } ++i; } if (llGetListLength(avatarList) > 0) { state dialog; } } } state dialog { state_entry() { // Set up a listener to detect button clicks. dlgHandle = llListen(dlgChannel, "", llGetOwner(), ""); // Start a new timer. llSetTimerEvent(30.0); // Add a 'Cancel' button. avatarList += ["Cancel"]; // Display the dialog. llDialog(llGetOwner(), "Please select an avatar.", avatarList, dlgChannel); } listen(integer channel, string name, key id, string message) { // The message parameter holds the caption of the // button that was clicked. Search the menu options // list for it. if ((channel == dlgChannel) && (llListFindList(avatarList, [message]) != -1)) { if (message != "Cancel") { llSay(0, llKey2Name(llGetOwner()) + " pokes " + message); } reset(); state default; } } timer() { reset(); state default; } }
Close the Build dialog, and your HUD should be fully active. Click on the buttons to check that they work.
Congratulations, you’ve just built your first HUD!
31 comments
Comments feed for this article
December 5, 2007 at 4:37 pm
Otenth Paderborn
One caution, Mr Morgridge. Just as 10m is the maximum length for any dimension in a prim, so is .01m the minimum. If you have any dimension of any component prim set at .01, you will not be able to reduce the object in size.
Since depth is irrelevant in a HUD, I suggest that the X value be set somewhat larger than .01m to allow for the size adjustment while attached that you suggest.
Another tip that I have found most useful: When editing an attached HUD, if you zoom out, you will see an indicator of the edge of your visible screen, and you can see any objects attached to HUD points that fall outside your range of vision.
December 6, 2007 at 1:24 pm
pyter
Thanks for that. Yes, I’d forgotten about the 0.1m minimum limit, and I didn’t know about the indicator at all. Learn something new every day!
December 7, 2007 at 9:29 pm
möök
Don’t shoot me, but I tagged you!! Now, give us your 8 random facts !! :-))
Greetz Ep
http://eppie.my-secondlife.nl
December 18, 2007 at 7:46 am
Script Snippets, 8: Text Output for a HUD « A View From Another Life
[…] LSL Script, Scripting, Second Life Tags: display, HUD, output, Scripting, Second Life In my previous blog entry about creating a HUD, I briefly mentioned that it was possible, but not necessarily easy, to have dynamic output on a […]
January 23, 2008 at 8:43 pm
martin
hi i was trying this script to make a teleporting HUD with buttons to different place in my island, but when i put the usual teleporting script and wear the hud and then if i press the button then it says right click and then click teleport, but some how when i right click then the entire hud edit window is coming and not the buttons edit window, i had to again check the “edit linked parts” check box to edit the info of the button
can u help me with this?? how can i get it to work for teleporting
January 23, 2008 at 9:53 pm
pyter
The problem is that because the HUD is made of linked prims, SL treats them as a single object. I can’t off-hand think of a simple way round this — I take it that your teleport script is using the ‘sit target’ hack (that’s the usual way).
What you could do is to have buttons to select the teleport target, then have a single ‘teleport’ button (this would have to be the root prim) that does the actual teleport. As a matter of fact, that sounds like an interesting little project. I’ll have a think, and if you contact me in-world, perhaps I can come up with something.
January 24, 2008 at 12:07 am
martin
how can i contact u in second life
January 24, 2008 at 1:21 am
martin
well i tried making the root prim to teleport but even that did not seem to work
January 24, 2008 at 11:58 pm
Klara
I have been trying this also to make a HUD I can program with quick links to places in a SIM they work if you put it down but not if you either wear it or do the button thing. Is there an “on wear” event that can fire a teleport action rather than a sit event? That would do for me. It would probably be safer if the script fires a “stop wearing” even once the TP has finished though. Any thoughts?
January 25, 2008 at 12:09 am
Klara
Small bug in your script:
I think the line “while((i < num_detected) && (i 0)” should say “while((i 0)”
January 25, 2008 at 12:10 am
Klara
between the “i” and the “o” there is a maths “greater than” character but it doesn’t load into this blog
February 24, 2008 at 2:48 am
GM Nikolaidis
Is there any way to get the object to speak as the owner, rather than as the object name?
February 24, 2008 at 11:01 am
pyter
Yes…and no. 🙂
When an object ‘speaks’, it displays it’s own name, so you could change the name of the object to the name of the owner. You can do this in a script with:
llSetObjectName(llKey2Name(llGetOwner()));
This works, but the object’s chat will still be displayed in green, indicating that an object is speaking rather than the actual avatar. This is to avoid abuse, because otherwise an object could maliciously impersonate an avatar.
November 2, 2008 at 5:00 pm
Chili
Thanks a lot, just what I have been missing for such a long time. I use it for controlling my light show, a very simple script in each button. Channel and colour, and same colour on the button.
default
{
touch_start(integer total_number)
{
llShout(4, “Magenta”);
}
}
June 5, 2009 at 8:12 am
Miss Shye
I am new to making a HUD and this helped me a lot 🙂 Also new to scripting
Was wondering, how do you push a whole group of people away that won’t stop bugging you? Please help. ._.
December 25, 2009 at 8:59 am
Shadowblaster Haggwood
Buy a good defense Hud 0.o
August 15, 2009 at 2:22 pm
Lolly Euler
I’d like to add some animations so that I can dance my favorite, or walk in an odd way. What script modifications shall I make?
September 2, 2009 at 8:45 pm
Zizawar
I am new to HUD. I try but confused. Kindly please give me more detail advise to joysmilelol@yahoo.com.
Once I attach HUD and select center, all disappeared. I am still lost it. Please help me.. Plzzz
January 13, 2010 at 8:35 pm
Canadiana Pixelmaid
I’m curious how this will accomodate a larger crowd of people since the llDialog is limited to only 12 buttons. How can we make it show 2 or 3 pages of people when needed.
June 28, 2010 at 11:08 am
Anonymous
Perfect example thanks!!!!
December 26, 2010 at 12:34 am
Alusión (weekly) « Alusión…Llamada Virtual
[…] Scripting Snippets, 7: Creating a HUD « A View From Another Life […]
December 26, 2010 at 12:34 am
PI (weekly) « PI en Second Life
[…] Scripting Snippets, 7: Creating a HUD « A View From Another Life […]
February 26, 2011 at 8:12 pm
Marlee
Is it possible to create a teleport menu via llDialog? I have the shell Dialog script, but need to add the destination target script in the ‘add an event’ line under each chosen button.
April 3, 2011 at 6:08 pm
candycane luv
I am trying to make a tummy talker and i am pretty new to makeing huds and have no scripting experience any suggestions
May 21, 2012 at 1:10 am
Anonymous
I was wondering if it was possible to have the button menu in with the scaning scritp…like a 12 button menu..
May 22, 2012 at 11:53 am
Dixy Dreamscape
I want to make a Emoting HUD That Can Emote KIsses & Hearts To Someone. My daughter Green Gemini is a singer in SL and I want to make her a Concert HUD for her Birthday. How Do I Go About Doing This With my limited knowledge of scripts.
June 8, 2012 at 10:15 am
CreaLogica
Firstly, thanks for your post, it really helped me.
The first time I tried to test this script,an avatar with more than 24 characters in their name was in range.
For those who don’t know, dialogs get narky at 24 characters:
llDialog: button labels must be 24 or fewer characters long
This was my quick workaround:
sensor(integer num_detected)
{
integer i;
while((i < num_detected) && (i 23)
{
avatarList += (string)llDeleteSubString((string)[llDetectedName(i)], 23, (integer)llStringLength((string)[llDetectedName(i)]));
}
else
{
avatarList += [llDetectedName(i)];
}
}
++i;
}
if (llGetListLength(avatarList) > 0)
{
state dialog;
}
}
This can definitely be improved upon, it’s just my crazy way of debugging.
August 20, 2012 at 10:12 am
shams
nicely explained, thank you,
Can some one help me with a little script which triggers animations, appreciated.
August 20, 2012 at 10:16 am
shams
i think its touch_start then the animation name, but dont know how to use it.
November 10, 2013 at 12:32 am
Nevea Cerise
Thank you for this very useful article!! I am making a hud from scratch, in order to change textures on mesh clothing. I have 8 buttons only and each texture will go on each button. Is there a script out there to put in each button? Or, does the script just go in the main root prim? Also, do I have to add the actual texture to each button ( in the contents of the button ) Much Thanks in advance to any and all help I can get!! Nevea Cerise
December 10, 2021 at 10:15 pm
Elayne
integer CharacterNamePrim;
integer CharacterHealthPrim;
GetLinkNames()
{
integer Loop;
for(Loop=1;Loop<=llGetNumberOfPrims();++Loop)
{
if(llGetLinkName(Loop)=="CharacterNamePrim")
{
CharacterNamePrim=Loop;
}
else if(llGetLinkName(Loop)=="CharacterHealthPrim")
{
CharacterHealthPrim=Loop;
}
touch_start(integer total_number)
{
key OwnerKey=llGetOwner();
key toucher = llDetectedKey(0);
integer button = llDetectedLinkNumber(0);
if (toucher==OwnerKey)
{
if(button==CharacterNamePrim)
{
something();
}
}