Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Dialog Dynamic_Dialog_Menu_Template  

Dynamic_Dialog_Menu_Template

Dynamic_Dialog_Menu_Template

Category: Dialog
By : mangowylder
Created: 2011-04-18 Edited: 2011-04-18
Worlds: Second Life

the Zip file

Download all files for Dynamic_Dialog_Menu_Template
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Dynamic_Dialog_Menu_Template_1.lsl
1 // This is a template script that will allow you to dynamically add
2 // or delete buttons from LLDialog boxes.
3 // In and of itself it does nothing more than to allow you to add/delete buttons with names
4 // and click on the buttons to tell you the button name you clicked on.
5 // However once those buttons are generated and named you can add functions
6 // to them so that they do usefull stuff.
7 // Maximum of 21 buttons. llDialog boxes can have a maximum of 12 buttons.
8 // 10 buttons in gLstChoicesButtons because it will always have the << Back button
9 // and the dynamicaly generated More button when gIntButtons is reached.
10 // 11 buttons in gLstChoicesButtons1 because it will always have the <<< Back button
11 // Max button vales are set at 3 and 4 for testing purposes.
12
13 // Written by,
14 // Mango Wylder //
15
16 //Globals//
17 list gLstChoices = ["Add Button", "ShowButtons", "Del Button"];
18 list gLstChoicesButtons = ["<< Back"];
19 list gLstChoicesButtons1 = ["<<< Back"];
20 // list to prevent the user from deleting the hard coded back buttons
21 // or the dynamically generated More button
22 list gLstForbidden = ["<< Back", "More", "<<< Back"];
23 integer gIntButtons = 3;
24 integer gIntButtons1 = 4;
25 integer gIntChannel_Dialog;
26 integer gIntChannel_Chat;
27 integer gIntListen_Id;
28 integer gIntListen_Id_Chat;
29 integer gIntAddButton;
30 integer gIntDelButton;
31 integer gIntDialog = 0;
32 string gStrButton;
33 key gKeyToucherID;
34
35 default{
36 state_entry() {
37 gIntChannel_Dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) ); // set a negative integer chat channel for the dialog box
38 gIntChannel_Chat = 7; // Set a chat channel to listen to owners commands
39 }
40
41 touch_start(integer total_number) {
42 gKeyToucherID = llDetectedKey(0);
43 llDialog(gKeyToucherID, "Please make a choice.", gLstChoices, gIntChannel_Dialog);
44 gIntListen_Id = llListen(gIntChannel_Dialog, "", gKeyToucherID, "");
45 llSetTimerEvent(20); // set a time limit to llListen
46 }
47
48 listen(integer channel, string name, key id, string choice) {
49 if(channel == gIntChannel_Dialog) {
50 if(~llListFindList(gLstChoices, [choice])) { // verify dialog choice
51 if(choice == "ShowButtons"){
52 // we know there are no buttons because list length is 1 and
53 // that's the << Back button
54 if(llGetListLength(gLstChoicesButtons) == 1) {
55 llOwnerSay("There are no Buttons to show. Try adding a button first!");
56 }
57 else
58 llDialog(gKeyToucherID, "What do you want to do?", gLstChoicesButtons, gIntChannel_Dialog);
59 }
60 if(choice == "Add Button") {
61 if(gIntDialog == 0) {
62 if(llGetListLength(gLstChoicesButtons) >= gIntButtons) {
63 // we have reached the maximum amount of buttons allowed in
64 // gLstChoicesButtons so we add a More button so we can
65 // see what's on gLstChoicesButtons1
66 gLstChoicesButtons = gLstChoicesButtons + ["More"];
67 gIntDialog = 1;
68 }
69 else {
70 gIntAddButton = 1;
71 llOwnerSay("Please enter a name for this Button in Local Chat on Channel /7");
72 gIntListen_Id_Chat = llListen(gIntChannel_Chat, "", gKeyToucherID, "");
73 llListenRemove(gIntListen_Id); // remove the listen on channel_dialog
74 }
75 }
76 if(gIntDialog == 1) {
77 if(llGetListLength(gLstChoicesButtons1) >= gIntButtons1) {
78 llOwnerSay("You have reached the maximum allowed Buttons!");
79 llOwnerSay("Please Delete a Button if you would like to add another.");
80 }
81 else {
82 gIntAddButton = 1;
83 llOwnerSay("Please enter a name for this Button");
84 gIntListen_Id_Chat = llListen(gIntChannel_Chat, "", gKeyToucherID, "");
85 llListenRemove(gIntListen_Id); // remove the listen on channel_dialog
86 }
87 }
88 }
89 if(choice == "Del Button") {
90 // we know there are no buttons to delete because list length is 1
91 // and that's the << Back button
92 if(llGetListLength(gLstChoicesButtons) == 1) {
93 llOwnerSay("There are no Buttons to delete");
94 }
95 else {
96 llOwnerSay("Please enter a name for Button you want to Delete on Channel /7");
97 gIntListen_Id_Chat = llListen(gIntChannel_Chat, "", gKeyToucherID, "");
98 gIntDelButton = 1;
99 llListenRemove(gIntListen_Id); // remove the listen on channel_dialog
100 }
101 }
102 }
103
104 if(~llListFindList(gLstChoicesButtons, [choice])){ // is choice here? 10 choices can be here
105 integer x = (llListFindList(gLstChoicesButtons, [choice]));
106 gStrButton = (llList2String(gLstChoicesButtons, x));
107 if(choice == "<< Back") {
108 llDialog(gKeyToucherID, "What do you want to do?", gLstChoices, gIntChannel_Dialog);
109 }
110 else if(choice == "More") {
111 llDialog(gKeyToucherID, "What do you want to do?", gLstChoicesButtons1, gIntChannel_Dialog);
112 }
113 else {
114 //Do something useful here//
115 llOwnerSay("You have pushed the " + gStrButton+ " button");
116 }
117 }
118
119 if(~llListFindList(gLstChoicesButtons1, [choice])){ // or is choice here? 11 choices can be here
120 integer y = (llListFindList(gLstChoicesButtons1, [choice]));
121 gStrButton = (llList2String(gLstChoicesButtons1, y));
122 if(choice == "<<< Back") {
123 llDialog(gKeyToucherID, "What do you want to do?", gLstChoicesButtons, gIntChannel_Dialog);
124 }
125 else {
126 //Do something useful here//
127 llOwnerSay("You have pushed the " + gStrButton+ " button");
128
129 }
130 }
131 }
132 // end channel dialog
133
134 if(channel == gIntChannel_Chat){
135 // Add Buttons section
136 if(gIntAddButton == 1){
137 if(gIntDialog == 0) {
138 gLstChoicesButtons = gLstChoicesButtons + [choice];
139 gIntAddButton = 0;
140 llOwnerSay("Button " + choice + " Saved!");
141 llListenRemove(gIntListen_Id_Chat);
142 }
143 if(gIntDialog == 1) {
144 gLstChoicesButtons1 = gLstChoicesButtons1 + [choice];
145 gIntAddButton = 0;
146 llOwnerSay("Button " + choice + " Saved!");
147 llListenRemove(gIntListen_Id_Chat);
148 }
149 }
150 // Delete Buttons section
151 if(gIntDelButton == 1) {
152 integer i = (llListFindList(gLstChoicesButtons + gLstChoicesButtons1, [choice]));
153 if(i == -1) {
154 llOwnerSay("That Button doesn't exist!. Please try again.");
155 gIntDelButton = 0;
156 llListenRemove(gIntListen_Id_Chat);
157 }
158 // prevent the user from deleting the hard coded back buttons
159 // or the dynamically generated More button
160 if(~llListFindList(gLstForbidden, [choice])){
161 llOwnerSay("Naughty, Naughty!. You can't remove that button!)");
162 gIntDelButton = 0;
163 }
164 else if(~llListFindList(gLstChoicesButtons, [choice])){
165 //if((gIdxLstDel = (~llListFindList(gLstChoicesMore, [choice])))){
166 integer j = (llListFindList(gLstChoicesButtons, [choice]));
167 gLstChoicesButtons = llDeleteSubList(gLstChoicesButtons, j,j);
168 llOwnerSay("Button " + choice + " removed");
169 gIntDelButton = 0;
170 llListenRemove(gIntListen_Id_Chat);
171 }
172 else if(~llListFindList(gLstChoicesButtons1, [choice])){
173 integer k = (llListFindList(gLstChoicesButtons1, [choice]));
174 gLstChoicesButtons1 = llDeleteSubList(gLstChoicesButtons1, k,k);
175 // if only the <<< Back button exists in gLstChoicesButtons1
176 // we have no need for the More button in gLstChoicesButtons
177 // so if it's there, delete it.
178 if(llGetListLength(gLstChoicesButtons1) == 1) {
179 if(~llListFindList(gLstChoicesButtons, ["More"])){
180 integer l = (llListFindList(gLstChoicesButtons, ["More"]));
181 gLstChoicesButtons = llDeleteSubList(gLstChoicesButtons, l,l);
182 gIntDialog = 0;
183 }
184 }
185 llOwnerSay("Button " + choice + " removed");
186 gIntDelButton = 0;
187 llListenRemove(gIntListen_Id_Chat);
188 }
189 }
190 }
191 }
192
193 timer() { //TIME’S UP!
194 llListenRemove(gIntListen_Id_Chat);
195 llListenRemove(gIntListen_Id);
196 llSetTimerEvent(0); //Stop the timer from being called repeatedly
197 }
198 }

Back to the Best Free Tools in Second Life and OpenSim.