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
Menu Generalized_Menu_Engine  

Generalized_Menu_Engine

General Menu Engine
This is a library...

Category: Menu
By : Zonax Delorean
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Generalized_Menu_Engine
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Generalized_Menu_Engine_1.lsl
Get file # 2. Generalized_Menu_Engine_2.lsl
Get file # 3. Generalized_Menu_Engine_3.lsl
1 // Menu Engine - v 1.0.2
2 // by Zonax Delorean
3 // License: BSD, but please provide patches/bugfixes if you can!
4
5 integer LM_DOMENU = 10001;
6 integer LM_OPTIONDATA = 10002;
7 integer LM_MENULOADED = 10003;
8 integer LM_RESETMENUSYSTEM = 10004;
9 integer LM_READSTRING = 10005;
10 integer LM_READSTRINGDATA = 10006;
11 integer LM_CUSTOMMENU = 10007;
12
13 string confNoteName = "menudefs";
14 integer cLine;
15 key cqid;
16
17 integer MC_TEXT = 1;
18 integer MC_TOMENU = 2;
19 integer MC_OPTION = 3;
20 integer MC_OPTIONASK = 4;
21 integer MC_END = 999;
22 // ...
23
24 integer numMenus;
25 list menudata;
26 list menuOffsets;
27 integer MENUREC_SIZE = 4;
28
29 integer debug = FALSE;
30
31 emitMsgSender( integer num, string msg ) {
32 if(debug) debugSay("Emit MSG: chn#"+(string)num+" : "+msg);
33 llMessageLinked(llGetLinkNumber(),num,msg,cUser);
34 }
35 emitMsgGlobal( integer num ) {
36 if(debug) debugSay("Emit MSG Global: chn#"+(string)num+" : ");
38 }
39
40 debugSay( string st ) {
41 llSay(0,st);
42 }
43
44 string clMenuID;
45 list clButtons;
46 list clActions;
47 string clMenuText;
48
49 // read data
50 startReadConfig() {
51 numMenus = 0;
52 menudata = [];
53 menuOffsets = [];
54 clMenuID = "";
55 clButtons = [];
56 clActions = [];
57 clMenuText = "";
58
59 cLine = 1;
60 cqid = llGetNotecardLine( confNoteName, cLine - 1 ); // request first line
61 }
62
63 commitEntry() {
64 // [ menuID, startOffset, startOffsetActions, endOffset ]
65 integer sofs = llGetListLength(menudata);
66 menuOffsets += [ clMenuID, sofs, sofs + 1 + llGetListLength(clButtons), sofs + 1 + llGetListLength(clButtons) + llGetListLength(clActions) ];
67 menudata += [ clMenuText ];
68 menudata += clButtons;
69 menudata += clActions;
70
71 clMenuID = "";
72 clMenuText = "";
73 clButtons = [];
74 clActions = [];
75 }
76
77 readConfigLine( string data ) {
78 if(data != EOF) {
79 integer spos = llSubStringIndex(data," ");
80 if(spos==-1) jump LreadNextLine; // not a line with space
81
82 string cmd = llGetSubString( data, 0, spos - 1);
83 data = llGetSubString( data, spos+1, -1);
84
85 integer cmdid = llListFindList(["MENU","TEXT","TOMENU","OPTION","OPTIONASK"],[cmd]);
86 if(cmdid==-1) jump LreadNextLine; // not a command
87
88 if(cmdid==0) { // MENU
89 if(clMenuID!="") commitEntry();
90 clMenuID = data;
91 }
92 else if(cmdid==1) { // TEXT
93 if(clMenuText!="") clMenuText += "\n";
94 list tmpl = llParseString2List(data,["\\n"],[]);
95 data = llDumpList2String(tmpl,"\n");
96 clMenuText += data;
97 }
98 else if(cmdid==2) { // TOMENU <MenuID> <ButtonText> or TOMENU <MenuID>
99 integer wpos = llSubStringIndex(data," ");
100 string tomenuid = data;
101 string btext = data;
102 if(wpos>=0) {
103 tomenuid = llGetSubString(data,0,wpos - 1);
104 btext = llGetSubString(data,wpos+1,-1);
105 }
106
107 clButtons += [ btext ];
108 clActions += [ MC_TOMENU, tomenuid ];
109 }
110 else if(cmdid==3) { // OPTION <ButtonText>
111 clButtons += [ data ];
112 clActions += [ MC_OPTION, data ];
113 }
114 else if(cmdid==4) { // OPTIONASK <ButtonText>
115 clButtons += [ data ];
116 clActions += [ MC_OPTIONASK, data ];
117 }
118
119 @LreadNextLine; // jump point
120 cLine++;
121 cqid = llGetNotecardLine( confNoteName, cLine - 1 );
122 } else {
123 if(clMenuID!="") commitEntry();
124 numMenus = llGetListLength(menuOffsets) / MENUREC_SIZE;
125 configLoaded();
126 }
127 }
128
129 //
130 // gets called when the config is done loading
131 //
132 configLoaded() {
133 if(debug) {
134 debugSay("Menu data loaded, mem: "+(string)llGetFreeMemory());
135 llInstantMessage(llGetOwner(),"OFS: "+llDumpList2String(menuOffsets,","));
136 llInstantMessage(llGetOwner(),"DATA: "+llDumpList2String(menudata,","));
137 }
138
139 // signal a message to the main prog
140 emitMsgGlobal(LM_MENULOADED);
141 }
142
143 string cMenuName;
144 integer cMenuNum;
145 integer CHATBASECHANNEL = 100050;
146 integer cOfs; // current menu start offset
147 key cUser; // current user
148 integer nList;
149 integer isListening = FALSE;
150 float RESPONSE_TIMEOUT = 60.0;
151 list cButtons;
152 list cActions;
153 integer cMenuType;
154 integer MT_ASK = 2;
155 integer MT_NORMAL = 1;
156 integer MT_READSTRING = 3;
157 integer MT_CUSTOM = 4;
158 integer cSenderID;
159
160 clearListens() {
161 if(isListening) {
162 llListenRemove(nList);
163 isListening = FALSE;
164 }
165 }
166
167 integer getMenuNum( string menuid ) {
168 integer c;
169 for (c=0;c<numMenus;c++)
170 if(llList2String(menuOffsets,c*MENUREC_SIZE) == menuid)
171 return(c);
172 return(-1);
173 }
174
175 // load a data for a menu and start a dialog
176 doMenu( key user, string menuname ) {
177 if(debug) debugSay("Do menu: "+menuname);
178 integer mnum = getMenuNum(menuname);
179 if( mnum == -1 ) { // menu not found
180 llSay(0,"Error: no such menu: "+menuname);
181 return;
182 }
183
184 cOfs = llList2Integer( menuOffsets, mnum * MENUREC_SIZE + 1 );
185 integer actOfs = llList2Integer( menuOffsets, mnum * MENUREC_SIZE + 2 );
186 integer actEnd = llList2Integer( menuOffsets, mnum * MENUREC_SIZE + 3 );
187
188 cMenuNum = mnum;
189 cMenuName = menuname;
190 cUser = user;
191 cButtons = llList2List( menudata, cOfs+1, actOfs - 1 );
192 cActions = llList2List( menudata, actOfs, actEnd );
193 cMenuType = MT_NORMAL; // normal menu
194
195 clearListens();
196 nList = llListen( CHATBASECHANNEL + cMenuNum, "", user, "");
197 isListening = TRUE;
198 llDialog( user, llList2String( menudata, cOfs ), cButtons, CHATBASECHANNEL + cMenuNum );
199 llSetTimerEvent(RESPONSE_TIMEOUT);
200 }
201
202
203 // param: <TEXT>
204 doAskMenu( key user, string param ) {
205 cMenuType = MT_ASK;
206 cButtons = [ "Yes", "No" ];
207 cActions = [ param ];
208 clearListens();
209 nList = llListen( CHATBASECHANNEL + cMenuNum, "", user, "");
210 isListening = TRUE;
211 llDialog( user, param, cButtons, CHATBASECHANNEL + cMenuNum );
212 llSetTimerEvent(RESPONSE_TIMEOUT);
213 }
214
215 ////////////////////////////////////////////
216 default
217 {
219 {
220 if(debug) llSay(0, "Loading menu... mem: "+(string)llGetFreeMemory());
221 startReadConfig();
222 }
223
224 dataserver(key query_id, string data) {
225 if(query_id==cqid) readConfigLine(data);
226 }
227
228 listen( integer channel, string name, key id, string message ) {
229 llSetTimerEvent(0.0);
230 clearListens();
231
232 if(cMenuType==MT_ASK) {
233 if(message=="Yes") {
234 string param = llList2String( cActions, 0 ); // special case
235 emitMsgSender(LM_OPTIONDATA,llDumpList2String([ cMenuName, param ],"|"));
236 }
237 return;
238 }
239 if(cMenuType==MT_CUSTOM) {
240 emitMsgSender(LM_OPTIONDATA,llDumpList2String([ cMenuName, message ],"|"));
241 return;
242 }
243 if(cMenuType==MT_READSTRING) {
244 string param = llList2String( cActions, 0 ); // special case
245 emitMsgSender(LM_READSTRINGDATA,llDumpList2String([ param, message ],"|"));
246 return;
247 }
248
249 integer c;
250 integer nb = llGetListLength(cButtons);
251 integer fnd = -1;
252 for (c=0;c<nb;c++) {
253 if(llList2String(cButtons,c)==message) {
254 fnd = c;
255 jump doneSR;
256 }
257 }
258 @doneSR;
259 if(fnd>=0) {
260 integer act = llList2Integer( cActions, fnd * 2 );
261 string param = llList2String( cActions, fnd * 2 + 1 );
262 if(debug) {
263 debugSay("r: "+(string)act+" "+param);
264 }
265 if(act==MC_TOMENU) {
266 string tomenu = param;
267 integer spos = llSubStringIndex(tomenu," ");
268 if(spos>=0) tomenu = llGetSubString(tomenu,0,spos - 1);
269
270 doMenu(id,tomenu);
271 return;
272 }
273 if(act==MC_OPTION) {
274 emitMsgSender(LM_OPTIONDATA,llDumpList2String([ cMenuName, param ],"|"));
275 return;
276 }
277 if(act==MC_OPTIONASK) {
278 doAskMenu(id,param);
279 return;
280 }
281
282 }
283 }
284
285 link_message(integer sender_num, integer num, string str, key id) {
286 if(num==LM_DOMENU) {
287 cSenderID = sender_num;
288 doMenu(id,str);
289 return;
290 }
291 if(num==LM_READSTRING) {
292 cSenderID = sender_num;
293 cMenuType = MT_READSTRING;
294
295 string message = str;
296 string retval = str;
297 integer spos = llSubStringIndex(str," ");
298 if(spos>=0) {
299 message = llGetSubString( str, spos+1, -1 );
300 retval = llGetSubString( str, 0, spos - 1 );
301 }
302 cActions = [ retval ];
303 nList = llListen( 0, "", id, ""); // listen from the user only
304 isListening = TRUE;
305 llSay(0,message);
306 llSetTimerEvent(RESPONSE_TIMEOUT);
307 return;
308 }
309 if(num==LM_CUSTOMMENU) {
310 list par = llParseString2List(str,["~|~"],[]);
311
312 if(llGetListLength(par)<2) {
313 llSay(0,"Error: not enough parameters for custom menu");
314 return;
315 }
316
317 cMenuName = llList2String(par,0);
318 string message = llList2String(par,1);
319 cUser = id;
320 cButtons = llList2List( par, 2, llGetListLength(par) - 1 );
321 cMenuType = MT_CUSTOM;
322
323 clearListens();
324 nList = llListen( CHATBASECHANNEL, "", cUser, "");
325 isListening = TRUE;
326 llDialog( cUser, message, cButtons, CHATBASECHANNEL );
327 llSetTimerEvent(RESPONSE_TIMEOUT);
328 return;
329 }
330 if(num==LM_RESETMENUSYSTEM) {
332 }
333 }
334
335 timer() {
336 llSetTimerEvent(0.0);
337 clearListens();
338 }
339 }

Generalized_Menu_Engine

The "menudefs" notecard:

Category: Menu
By : Zonax Delorean
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 MENU DEFAULT
2 TEXT ~ Main Menu ~\nSelect a function
3 TOMENU SETTITLE Set title
4 OPTION Start vote
5 TOMENU CLITEM Clear Item
6 OPTIONASK Reset
7
8 MENU SETTITLE
9 TEXT Set title for which item?
10 OPTION 1
11 OPTION 2
12 OPTION 3
13
14 MENU CLITEM
15 TEXT Clear title and picture for which item?
16 OPTION 1
17 OPTION 2
18 OPTION 3
19
20 MENU INVOTE
21 TEXT Voting in progress...
22 OPTIONASK Clear votes
23 OPTIONASK Close voting
24
25 MENU VOTEDONE
26 TEXT Vote closed
27 OPTIONASK Restart voting
28 OPTION Tell results

Generalized_Menu_Engine


A "MenuDemo" script:

Category: Menu
By : Zonax Delorean
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 // Menu demo program
2
3 //--- Menu library interface start-------------
4 integer LM_OPTIONDATA = 10002;
5 integer LM_MENULOADED = 10003;
6 integer LM_READSTRINGDATA = 10006;
7
8 resetMenu() {
9 llMessageLinked(llGetLinkNumber(),10004,"",NULL_KEY); // 10004: LM_RESETMENUSYSTEM
10 }
11 doMenu( key user, string menuname ) {
12 llMessageLinked(llGetLinkNumber(),10001,menuname,user); // 10001: LM_DOMENU
13 }
14 readString( key user, string var, string prompt ) {
15 llMessageLinked(llGetLinkNumber(),10005,var+" "+prompt,user); // 10005: READSTRING
16 }
17 customMenu( key user, string menuname, string message, list buttons ) {
18 llMessageLinked(llGetLinkNumber(),10007,llDumpList2String([ menuname, message ] + buttons,"~|~"),user);
19 }
20 //---Menu Library inteface end----------
21
22 default
23 {
25 {
26 //resetMenu();
27 }
28
29 link_message(integer sender_num, integer num, string str, key id) {
30 if(num==LM_OPTIONDATA) {
31 llSay(0,"MenuOutput: "+str);
32 }
33 if(num==LM_MENULOADED) {
34 llSay(0,"Menu has just been (re)loaded");
35 }
36 if(num==LM_READSTRINGDATA) {
37 integer wpos = llSubStringIndex(str,"|");
38 string varname = llGetSubString(str,0,wpos - 1);
39 string response = llGetSubString(str,wpos+1,-1);
40 llSay(0,"Variable: "+varname+" String read: "+response);
41 }
42 }
43
44 touch_start(integer total_number)
45 {
46 doMenu(llDetectedKey(0),"DEFAULT");
47
48 // other things you can try (uncomment it)
49 //customMenu(llDetectedKey(0),"CUST1","Test custom menu",["Test A","Test B","Test C"]);
50 //readString(llDetectedKey(0),"FAVCOLOR","Please enter your favorite color in chat:");
51 }
52 }

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