As we discussed in general different functions, you can start talking about a very important command, that allows us to get a menu with the buttons. The function is
llDialog
() and require
-l 's avatar id to which it is addressed;
-the message string (the title of the menu that appears at the top, so to speak )
- the list of buttons ;
-L 'integer of listening channel on the menu.
A script immediately clarify the above: we could try writing a simple menu that allows you to choose which color to assign to a cube (say red, green and blue).
-L 'integer of listening channel on the menu. We therefore need to build a menu with three buttons (placed on a list), which allows to click to decide what color to assign.
immediately declare three global variables (list, channel and titoletto) who serve for our purpose and then insert the rest;
Here's the script:
list buttons = ["Red", "Blue", "Green "]; string
description = "Choose a color" default
{
llListen (channel, "", llDetectedKey
(0 ),"");
/ / start listening now
}
touch_start
(integer count) / / to the touch, run the menu
{ llDialog ( llDetectedKey (0), description, buttons, channel);}
listen (integer chan , string name, key id, string mes) {if (mes == "Red") / / if the message is red ....
{
(0, "My color turns red!");
llSetColor
(\u0026lt;1,0,0>, ALL_SIDES) ; } else if (mes == "Blue")
/ / otherwise if the message is blue .... llSay (0, "The My color turns blue! ");
llSetColor
(\u0026lt;0,0,1>, ALL_SIDES) } else if ( mes == "Green") / / otherwise if the message is green ....
{ llSay (0, "My color is green!");
llSetColor (\u0026lt;0.1 , 0>, ALL_SIDES)
}}}
The structure is simple: in the event we listen included three simple conditions .. If the message is Red ... etc. Otherwise
If the message is Blue .. Otherwise if the message is Green ... (care to use the == to check an equality) Notice how the messages have the same name of the buttons (a necessary condition for work.) The buttons can be a maximum of 12 per menu, and order taking, in relation to their placement on the list is as follows:
The menu is the basis for many things, so it is important to know the structure. also have noticed the use of a list (something I mentioned in the post on the variables), which is a container used to enclose a number of elements.
Also lists the most commonly encountered in the next examples.
ADVICE: The example above is very simple: consider for example that it is inelegant to leave a " llListen ()" always open, and that could be used by a timer to close llListenRemove (). Another curiosity: we set a fixed channel (-1234) .. what happens?
that if you put two cubes side (both with this script, on this channel) and pick up a color, the color will be applied to other!!
How do you solve? In very simple: set a random channel, which is extracted
when the object is rezzed. function
llFrand () we have already seen, and the one that chooses randomly after giving a value.
We make the following changes to the code: take away: integer channel = -1234; entered:
integer channel; Part FIRST touch event becomes the following
default { on_rez (integer param) {
llResetScript
(); / / Reset any rez, for a channel always different } state_entry () {
channel = (integer) llFrand
(20000.0) +1; llListen (channel, "",
(0} ),"");
If you want "proof" that your channel is always different on every rez, just enter a llSay () tell you the channel: state_entry
() ; {channel = (integer ) llFrand (20000.0) +1;
llListen (channel, "",
llDetectedKey (0 ),""); llSay (0, (
string) channel); / / see for yourself the channel! }
all for now .... Happy testing!
integer channel = -1234;
() {
0 comments:
Post a Comment