Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Example HUD with a Dialog and Floating Text

Clayton Cinquetti
Registered User
Join date: 17 May 2005
Posts: 38
12-24-2006 16:16
Here's a simple HUD and Dialog example. What you get with this demo is a Heads Up Display (HUD) in the upper left hand corner of your screen. On the HUD is text that says “Click HUD for Dialog Options”. If you click the HUD a dialog box drops from the upper right hand corner of the screen. Depending on what dialog option you select, the text on the HUD will change. The description below outlines how to duplicate my results. Screenshots are available on my blog at secondlifehowto.com:

1. Create two blocks one on top of the other and link them together. Make the bottom box transparent and the top box textured with something that would be a good background for red text. Link the two boxes together.

2. Add the script below to the bottom box. What this script does is display the text “Click HUD for dialog of options” and then waits for a touch. When a touch occurs it creates a dialog and then listens for a response. When a response occurs the hovering text is updated.

3. Right click on linked boxes and select attach to HUD -> Center. I recommend you start with the center because if you start with your HUD in the corner it can sometimes be off the screen. You can use the edit button and adjust the position left and lower on the screen from the center HUD position so that when you move it to the upper left hand corner (if you want to) it will fit better.

That's about it.

Here's the code:
CODE

// when HUD touched, present a dialog with four color choices

integer CHANNEL = 42; // dialog channel
list MENU_MAIN = ["Sit", "Stand", "Fly", "Cheat", "Options..."]; // the main menu
list MENU_OPTIONS = ["Cherry", "Blueberry", "Vinegar", "Slime", "Chips", "Salad", "...Back"]; // a submenu

default {
state_entry()
{
llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)

// Set text to display in bright red
llSetText("Click HUD for dialog of options", <1,0,0>, 1.0);

}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "What do you want to do?", MENU_MAIN, CHANNEL); // present dialog on click
}


listen(integer channel, string name, key id, string message)
{
string response_string;

if (llListFindList(MENU_MAIN + MENU_OPTIONS, [message]) != -1) // verify dialog choice
{
//llSay(0, name + " picked the option '" + message + "'."); // output the answer
response_string = name + " picked the option '" + message + "'.";
if (message == "Options...")
llDialog(id, "Pick an option!", MENU_OPTIONS, CHANNEL); // present submenu on request
else if (message == "...Back")
llDialog(id, "What do you want to do?", MENU_MAIN, CHANNEL); // present main menu on request to go back
// here you have the name and key of the user and can easily verify if they have the permission to use that option or not
else if (message == "Sit")
{
//llSay(0, "This is where stuff would happen if this wasn't just an example");
response_string = "This is where stuff would happen if this wasn't just an example\n";
response_string = response_string + "Click HUD for dialog of options";
}
}
else
{
//llSay(0, name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice
response_string = name + " picked invalid option '" + llToLower(message) + "'.\n";
response_string = response_string + "Click HUD for dialog of options";
}

// Set text to display in bright red
llSetText(response_string, <1,0,0>, 1.0);

}
}

Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-24-2006 16:27
Nice job Clayton. Why don't you go ahead and post it to the library for the future scripters?
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum