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 Dialog_module  

Dialog_module

This script is a standalone module for the handling of dialog boxes.

Category: Dialog
By : Strife Onizuka
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Dialog_module
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Dialog_module_1.lsl
Get file # 2. Dialog_module_2.lsl
Get file # 3. Dialog_module_3.lsl
1 // The dialog boxes each use a random unique negative channel, for each dialog box.
2 // Channel numbers range from -2147483648 to -255 with the possibility of the lower 8 bits being zero.
3 // The listens are bound to the user's key. This means that no script or other user can activate the interface.
4 // By using a negative number there is no way for the user to type in a command and have it mistaken as a response.
5 // Only responses that are valid buttons from the requested user (and in the mask) will result in a return; no 3rd party tampering is possible.
6 // It would be very difficult for anyone to predict the channel number to listen on (2 billion is a big range).
7 //
8 // The Request:
9 // The link message string format is a list. The first element of this list is the integer that will be used as the second integer in the return the link message. The rest of this list is string that will be returned (in list form with the same separating character).
10 //
11 // The link message key format is a list. The first element is the key of the user, if this is left blank (or NULL_KEY) the owner is assumed. The second element is the message, this can be any valid string. The third element is a float, which is the dialog box time to live. The forth element is an integer it is used as a mask for when a button is pressed if it will trigger a response. The rest of the list is for the buttons; an empty list can be used, but it will default to ["OK"] (there is no way around this, just cope).
12 //
13 // The Response:
14 // The link message string format is a list. It is whatever was passed as the second string minus the first entry of that list.
15 // The link message key format is a list. The first element of this list is the number of the button pressed (or error code). The second entry is the text of the button pressed. The third entry is the key it used for creating the dialog box. The forth entry is the user name. The fifth entry is how much time was left in the time to live of the dialog box (not very useful but maybe it is).
16 // The response always goes back to only the prim that requested the dialog box.
17 //
18 // (string)dump(llList2List(parse(paramString),1,-1)),
19 // (key)dump([integer buttonNum, string buttonText, key user, string userName, float aproxTimeLeft],"")
20 //
21 //
22 // There is no way to create a dialog box that won't timeout. The value must be between 5.0 and 7200.0; or it will be replaced by the default timeout. The timeout won't make a box disapeer off the users screen, but the script will stop listening for results.
23 //
24 // Notes:
25 // Know your data; if your strings contain "|" then don't use "|" as the separator. If the script acts weirdly this is probably why. The separator can only be one character. The two different strings being passed in the linked message can use different separating characters.
26 //
27 // Misc:
28 // The ButtonMask has a few extra tricks.
29 // The first 12 bits corespond to the 12 buttons (bits 0 -> 11)
30 // Bits 16 through 22 are special bits for error handling and setup.
31 // All other bits are ignored, do with them as you please but be warned they may be used in the future.
32 // Bit Hex Value Event Return Button
33 // 0 0x000001 Button 0 Pressed 0
34 // 1 0x000002 Button 1 Pressed 1
35 // 2 0x000004 Button 2 Pressed 2
36 // 3 0x000008 Button 3 Pressed 3
37 // 4 0x000010 Button 4 Pressed 4
38 // 5 0x000020 Button 5 Pressed 5
39 // 6 0x000040 Button 6 Pressed 6
40 // 7 0x000080 Button 7 Pressed 7
41 // 8 0x000100 Button 8 Pressed 8
42 // 9 0x000200 Button 9 Pressed 9
43 // 10 0x000400 Button 10 Pressed 10
44 // 11 0x000800 Button 11 Pressed 11
45 // 16 0x010000 Dialog box times out -1
46 // 17 0x020000 Queue being cleared -2
47 // 18 0x040000 Target agent not found -3
48 // 19 0x080000 No buttons to listen for, bad mask or bad return channel -4
49 // 20 0x100000 Clears the queue then creates the dialog box -2 via Bit 17
50 // 21 0x200000 Same as bit 20 but only for boxes for the current user -2 via Bit 17
51 // 22 0x400000 Target agent has left the sim -5
52 //
53 // The queue is cleared in two ways: on_rez or when creating a dialog box requests it. When the script is rez'ed, the old dialog box requests become meaningless (because the script cannot receive the response). By having bit 17 on, it allows for this event to be returned to the script requesting the box. By having bit 20 turned on also causes the queue to be reset (exactly like an on_rez). Using bit 20 may have undesired effects if you are using this module with multiple scripts. Using bit 21 causes a partial clear. It clears out all boxes for the requested user; it is advisable to use this option instead of bit 20.
54 //
55 // Todo:
56 // When bits 20 and 21 are true have the inverse result happen. All boxes not of the current user would be cleared from the queue.
57 //
58 // Tricks:
59 // Pass a list of useful values as the return list. Have them correspond to the button list. Then use the code below to get that value from the return (remember if you have any of bits 16 -> 19 enabled you will get negative index values on errors).
60 //
61 // llList2String(parse(c),(integer)llList2String(parse(d),0));
62
63 string sepchar = "|";
64 integer answer = 546;
65 integer DialogComm = 12;
66
67 dialog(key user, string message, float timeout, list buttons, integer buttonmask, integer retchan, list ret)
68 {
69 llMessageLinked(llGetLinkNumber(), DialogComm, dump([retchan] + ret, sepchar),
70 dump([user, message, timeout, buttonmask] + buttons, sepchar));
71 }
72
73 string dump(list a, string b)
74 {
75 string c = (string)a;
76 if(1+llSubStringIndex(c,b) || llStringLength(b)!=1)
77 {
78 b += "|\\/?!@#$%^&*()_=:;~{}[],\n qQxXzZ";
79 integer d = -llStringLength(b);
80 while(1+llSubStringIndex(c,llGetSubString(b,d,d)) && d)
81 d++;
82 b = llGetSubString(b,d,d);
83 }
84 return b + llDumpList2String(a, b);
85 }
86
87 list parse(string a) {
88 string b = llGetSubString(a,0,0);//save memory
89 return llParseStringKeepNulls(llDeleteSubString(a,0,0), [b],[]);
90 }
91
92 default
93 {
95 {
96 integer rint = 6;
97 string question = "Would you like a drink?";
98 list Answers = ["Yes", "No", "Strongest"];
99 integer AnswerMask = 0x005;
100 list ExtraPassback = ["extra info to pass back"];
101 dialog(llGetOwner(), question, 30,Answers, AnswerMask , answer, ExtraPassback);
102 }
104 {
105 dialog(llDetectedKey(0), "Hello\nDo you like me?", 30, ["Yes", "No"], 0xf0fff, answer, ["I think they like us"]);
106 }
108 {
109 if(b==answer)
110 {
111 llWhisper(0,(string)b);
112 llWhisper(0,llList2CSV(parse(c)));
113 llWhisper(0,llList2CSV(parse(d)));
114 //c is the return list
115 //d is a list [button number pressed, user, time left, user name, button text]
116 }
117 }
118 }

Dialog_module


Dialog Module:

Category: Dialog
By : Strife Onizuka
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 //////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Dialog Module
4 // Version 9.3 Release
5 // Copyright (C) 2004-2006, Strife Onizuka
6 // http://home.comcast.net/~mailerdaemon/
7 // http://secondlife.com/badgeo/wakka.php?wakka=LibraryDialogModule
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public License
11 // as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public License
20 // along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 //////////////////////////////////////////////////////////////////////////////////////
24
25 //////////////////////////////////////////////////////////////////////////////////////
26 //Don't change anything else unless you *really* need to.
27
28 list handles;
29 list time;
30 list chans;
31 string users;//save memory
32 list answer;
33 list button;
34 list prim;
35 list mask;
36 list intchan;
37
38 integer ticks;
39
40 remove(integer a)
41 {
43 handles = llDeleteSubList(handles,a,a);
44 time = llDeleteSubList(time, a,a);
45 chans = llDeleteSubList(chans, a,a);
46 answer = llDeleteSubList(answer, a,a);
47 button = llDeleteSubList(button, a,a);
48 prim = llDeleteSubList(prim, a,a);
49 mask = llDeleteSubList(mask, a,a);
50 intchan = llDeleteSubList(intchan,a,a);
51 users = llDeleteSubString(users,a*=36,a+35);
52 }
53
54 list TightListParse(string a) {
55 string b = llGetSubString(a,0,0);//save memory
56 return llParseStringKeepNulls(llDeleteSubString(a,0,0), [a=b],[]);
57 }
58
59 clear()
60 {
61 integer a = llGetListLength(handles);
62 while(a)
63 {
64 llListenRemove(llList2Integer(handles,--a));
65 if(llList2Integer(mask,a)&0x20000)
67 llList2String(answer,a), "|-2||"+llGetSubString(users,a * 36,(a * 36) + 35)+"||-1");
68 }
69 llSetTimerEvent(ticks = 0);
70 }
71
72 default
73 {
75 {
76
77 llOwnerSay("Dialog Module, Version 9.2, Released Under the GNU Lesser General Public License");
78 llOwnerSay("Copyright (C) 2004-2006, Strife Onizuka, http://secondlife.com/badgeo/wakka.php?wakka=LibraryDialogModule");
79
80
81 }
83 {
84 clear();
85 }
87 {
88 if(b == 12)
89 {
91 list e = TightListParse(d);
92 integer buttonmask = (integer)llList2String(e,3);
93 string user = llList2String(e,0);
94 list buttons = llDeleteSubList(e,0,3);
95 float timeout = (float)llList2String(e,2);
96 integer cat = (integer)llFrand(-2147483392.0) - 255;
97 integer chan = (integer)llDeleteSubString(c, b + 1, 0);
98 string ans = llDeleteSubString(c,0,b);
99
100 if(buttonmask & 0x100000)
101 clear();
102 else if(buttonmask & 0x200000)
103 {//clean out other box's that went to this user.
104 while(1 + (b = llSubStringIndex(users, user)))
105 {
106 if(llList2Integer(mask,b/=36)&0x20000)
108 llList2String(answer,b), "|-2||"+llGetSubString(users,b * 36,(b * 36) + 35)+"||-1");
109 remove(b);
110 }
111 if(time == [])
112 llSetTimerEvent(ticks = 0);
113 }
114
115 if(user == "" || user == NULL_KEY) //lazy check
116 user = llGetOwner();
117 if(!llGetAgentInfo(user))
118 {// target not in the sim
119 if(buttonmask & 0x40000)
120 llMessageLinked(a, chan, ans, "|-3||"+user+"||0");
121 jump end1;//instead of a return, too many local variables to clear off the stack.
122 }
123 while(1+llListFindList(chans,[cat]))
124 --cat;
125
126 b = llListen(cat,"",user,"");
127 llDialog(user, llList2String(e,1), buttons, cat);
128 if(chan != 12)
129 {//loopback catch
130 if(buttons == []) // so we can match the ok button
131 buttons = ["OK"];
132 if(buttonmask & ((1<<llGetListLength(buttons)) - 1))
133 { //we checked the mask to see if we should expect any values back
134 chans += cat;
135 handles += b;
136 if(timeout < 5.0 || timeout > 7200)
137 timeout = 5.0;
138 time += (ticks + (timeout / 5.0));
139 users += user;
140 answer += ans;
141 button += (llGetSubString(d,0,0) + llDumpList2String(buttons, llGetSubString(d,0,0)));
142 prim += a;
143 mask += buttonmask;
144 intchan += chan;
145 llSetTimerEvent(5.0);
146 jump end2;//instead of a return, too many local variables to clear off the stack.
147 }
148 }
150 if(buttonmask & 0x80000)
151 llMessageLinked(a, chan, ans, "|-4||"+(string)user+"||0");
152 }
153 @end1;@end2;
154 }
155 listen(integer a, string b, key c, string d)
156 {
157 if(a+1 && llGetSubString(users,36 * a=llListFindList(chans,[a]),(a * 36) + 35) == c)
158 {//it's one of our listens
159 integer f = llListFindList(TightListParse(llList2String(button,a)),[d]);
160 if(f+1)
161 {//we matched a button
162 if(llList2Integer(mask,a)&(1<<f))
163 {
164 list ret = [f, d, c, b,(llList2Float(time,a) - ticks) * 5.0];
165 if(llSubStringIndex(d = (string)ret,b = "|") + 1)
166 {
167 f = -37;
168 b = "|\\/?!@#$%^&*()_=:;~{}[]<>`',\n\" qQxXzZ";
169 do;while(1+llSubStringIndex(d,llGetSubString(b,f,f)) && ++f);
170 b = llGetSubString(b,f,f);
171 }
172 d = "";
174 llList2String(answer,a), (b + llDumpList2String(ret, b)));
175 }
176 remove(a);
177 if(time == [])
178 llSetTimerEvent(ticks = 0);
179 }
180 }
181 }
182 timer()
183 {
184 ++ticks;
185 integer a = llGetListLength(time);
186 float c;
187 key d;
188 while(a)
189 {
190 if(((c = llList2Float(time,a)) <= ticks) || !llGetAgentInfo(d = llGetSubString(users,--a * 36,(a * 36) + 35)))
191 {
192 if(llList2Integer(mask,a)&0x10000)
194 llList2String(answer,a), "|-1||"+(string)d+"||"+(string)((ticks - c) * 5.0));
195
196 remove(a);
197 }
198 }
199 if(time == [])
200 llSetTimerEvent(ticks = 0);
201 }
202 }

Dialog_module

ESL Version:

Category: Dialog
By : Strife Onizuka
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 //////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Dialog Module
4 // Version 9.3 Release
5 // Copyright (C) 2004-2006, Strife Onizuka
6 // http://home.comcast.net/~mailerdaemon/
7 // http://secondlife.com/badgeo/wakka.php?wakka=LibraryDialogModule
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public License
11 // as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public License
20 // along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 //////////////////////////////////////////////////////////////////////////////////////
24
25 #ifndef DIALOGCOMM
26 #define DIALOGCOMM 12
27 #endif
28 #ifdef USESCRIPTNAME
29 integer DialogComm = DIALOGCOMM;
30 #elif !defined DialogComm
31 #define DialogComm DIALOGCOMM
32 #endif
33
34 #ifndef TICKSIZE
35 #define TICKSIZE 5.0
36 #endif
37 #ifndef DEFAULTTIMEOUT
38 #define DEFAULTTIMEOUT TICKSIZE
39 #endif
40 //////////////////////////////////////////////////////////////////////////////////////
41 //Don't change anything else unless you *really* need to.
42 #define ZERO_INTEGER 0
43 list handles;
44 list time;
45 list chans;
46 string users;//save memory
47 list answer;
48 list button;
49 list prim;
50 list mask;
51 list intchan;
52
53 integer ticks;
54
55 remove(integer a)
56 {
58 handles = llDeleteSubList(handles,a,a);
59 time = llDeleteSubList(time, a,a);
60 chans = llDeleteSubList(chans, a,a);
61 answer = llDeleteSubList(answer, a,a);
62 button = llDeleteSubList(button, a,a);
63 prim = llDeleteSubList(prim, a,a);
64 mask = llDeleteSubList(mask, a,a);
65 intchan = llDeleteSubList(intchan,a,a);
66 users = llDeleteSubString(users,a*=36,a+35);
67 }
68
69 #define wipe() llSetTimerEvent(ticks = ZERO_INTEGER)
70 #define quickdump(a, b) (b + llDumpList2String(a, b))
71 #ifndef quickdump
72 string quickdump(list a, string b){ return b + llDumpList2String(a, b); }
73 #endif
74
75 list TightListParse(string a) {
76 string b = llGetSubString(a,ZERO_INTEGER,ZERO_INTEGER);//save memory
77 return llParseStringKeepNulls(llDeleteSubString(a,ZERO_INTEGER,ZERO_INTEGER), [a=b],[]);
78 }
79
80 clear()
81 {
82 integer a = llGetListLength(handles);
83 while(a)
84 {
85 llListenRemove(llList2Integer(handles,--a));
86 if(llList2Integer(mask,a)&0x20000)
88 llList2String(answer,a), "|-2||"+llGetSubString(users,a * 36,(a * 36) + 35)+"||-1");
89 }
90 wipe();
91 }
92
93 default
94 {
96 {
97 #ifdef USESCRIPTNAME
98 if((DialogComm += (integer)llList2String(llParseString2List(llGetScriptName(), [" "],[]), -1)) == DialogComm)
99 {
100 #endif
101 llOwnerSay("Dialog Module, Version 9.2, Released Under the GNU Lesser General Public License");
102 llOwnerSay("Copyright (C) 2004-2006, Strife Onizuka, http://secondlife.com/badgeo/wakka.php?wakka=LibraryDialogModule");
103 #ifdef USESCRIPTNAME
104 }
105 #endif
106 }
108 {
109 clear();
110 }
112 {
113 if(b == DialogComm)
114 {
115 b = llSubStringIndex(llDeleteSubString(c,ZERO_INTEGER,ZERO_INTEGER), llGetSubString(c,ZERO_INTEGER,ZERO_INTEGER));
116 list e = TightListParse(d);
117 integer buttonmask = (integer)llList2String(e,3);
118 string user = llList2String(e,ZERO_INTEGER);
119 list buttons = llDeleteSubList(e,ZERO_INTEGER,3);
120 float timeout = (float)llList2String(e,2);
121 integer cat = (integer)llFrand(-2147483392.0) - 255;
122 integer chan = (integer)llDeleteSubString(c, b + 1, ZERO_INTEGER);
123 string ans = llDeleteSubString(c,ZERO_INTEGER,b);
124
125 if(buttonmask & 0x100000)
126 clear();
127 else if(buttonmask & 0x200000)
128 {//clean out other box's that went to this user.
129 while(1 + (b = llSubStringIndex(users, user)))
130 {
131 if(llList2Integer(mask,b/=36)&0x20000)
133 llList2String(answer,b), "|-2||"+llGetSubString(users,b * 36,(b * 36) + 35)+"||-1");
134 remove(b);
135 }
136 if(time == [])
137 wipe();
138 }
139
140 if(user == "" || user == NULL_KEY) //lazy check
141 user = llGetOwner();
142 if(!llGetAgentInfo(user))
143 {// target not in the sim
144 if(buttonmask & 0x40000)
145 llMessageLinked(a, chan, ans, "|-3||"+user+"||0");
146 jump end1;//instead of a return, too many local variables to clear off the stack.
147 }
148 while(1+llListFindList(chans,[cat]))
149 --cat;
150
151 b = llListen(cat,"",user,"");
152 llDialog(user, llList2String(e,1), buttons, cat);
153 if(chan != DialogComm)
154 {//loopback catch
155 if(buttons == []) // so we can match the ok button
156 buttons = ["OK"];
157 if(buttonmask & ((1<<llGetListLength(buttons)) - 1))
158 { //we checked the mask to see if we should expect any values back
159 chans += cat;
160 handles += b;
161 if(timeout < 5.0 || timeout > 7200)
162 timeout = DEFAULTTIMEOUT;
163 time += (ticks + (timeout / TICKSIZE));
164 users += user;
165 answer += ans;
166 button += quickdump(buttons,llGetSubString(d,ZERO_INTEGER,ZERO_INTEGER));
167 prim += a;
168 mask += buttonmask;
169 intchan += chan;
170 llSetTimerEvent(TICKSIZE);
171 jump end2;//instead of a return, too many local variables to clear off the stack.
172 }
173 }
175 if(buttonmask & 0x80000)
176 llMessageLinked(a, chan, ans, "|-4||"+(string)user+"||0");
177 }
178 @end1;@end2;
179 }
180 listen(integer a, string b, key c, string d)
181 {
182 if(a+1 && llGetSubString(users,36 * a=llListFindList(chans,[a]),(a * 36) + 35) == c)
183 {//it's one of our listens
184 integer f = llListFindList(TightListParse(llList2String(button,a)),[d]);
185 if(f+1)
186 {//we matched a button
187 if(llList2Integer(mask,a)&(1<<f))
188 {
189 list ret = [f, d, c, b,(llList2Float(time,a) - ticks) * TICKSIZE];
190 if(llSubStringIndex(d = (string)ret,b = "|") + 1)
191 {
192 f = -37;
193 b = "|\\/?!@#$%^&*()_=:;~{}[]<>`',\n\" qQxXzZ";
194 do;while(1+llSubStringIndex(d,llGetSubString(b,f,f)) && ++f);
195 b = llGetSubString(b,f,f);
196 }
197 d = "";
199 llList2String(answer,a), quickdump(ret, b));
200 }
201 remove(a);
202 if(time == [])
203 wipe();
204 }
205 }
206 }
207 timer()
208 {
209 ++ticks;
210 integer a = llGetListLength(time);
211 float c;
212 key d;
213 while(a)
214 {
215 if(((c = llList2Float(time,a)) <= ticks) || !llGetAgentInfo(d = llGetSubString(users,--a * 36,(a * 36) + 35)))
216 {
217 if(llList2Integer(mask,a)&0x10000)
219 llList2String(answer,a), "|-1||"+(string)d+"||"+(string)((ticks - c) * TICKSIZE));
220
221 remove(a);
222 }
223 }
224 if(time == [])
225 wipe();
226 }
227 }

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