corrade-lsl-templates – Blame information for rev 29

Subversion Repositories:
Rev:
Rev Author Line No. Line
4 office 1 ///////////////////////////////////////////////////////////////////////////
29 office 2 // Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 //
4 office 3 ///////////////////////////////////////////////////////////////////////////
4 //
5 // This is a menu selector for the Corrade bot that is capable of replying
6 // to dialog requests while supporting several nested levels of menus. You
7 // can find out more about the Corrade bot by following the URL:
8 // http://was.fm/secondlife/scripted_agents/corrade
9 //
10 // The sit script works together with a "configuration" notecard that must
11 // be placed in the same primitive as this script. The purpose of this
12 // script is to demonstrate answering dialogs with Corrade and you are free
29 office 13 // to use, change, and commercialize it under the CC BY 2.0 license at:
14 // https://creativecommons.org/licenses/by/2.0
4 office 15 //
16 ///////////////////////////////////////////////////////////////////////////
17  
18 ///////////////////////////////////////////////////////////////////////////
29 office 19 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 //
4 office 20 ///////////////////////////////////////////////////////////////////////////
21 string wasKeyValueGet(string k, string data) {
22 if(llStringLength(data) == 0) return "";
23 if(llStringLength(k) == 0) return "";
24 list a = llParseString2List(data, ["&", "="], []);
25 integer i = llListFindList(a, [ k ]);
26 if(i != -1) return llList2String(a, i+1);
27 return "";
28 }
29  
30 ///////////////////////////////////////////////////////////////////////////
29 office 31 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
4 office 32 ///////////////////////////////////////////////////////////////////////////
33 string wasKeyValueEncode(list data) {
34 list k = llList2ListStrided(data, 0, -1, 2);
35 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
36 data = [];
37 do {
38 data += llList2String(k, 0) + "=" + llList2String(v, 0);
39 k = llDeleteSubList(k, 0, 0);
40 v = llDeleteSubList(v, 0, 0);
41 } while(llGetListLength(k) != 0);
42 return llDumpList2String(data, "&");
43 }
44  
45 ///////////////////////////////////////////////////////////////////////////
29 office 46 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
4 office 47 ///////////////////////////////////////////////////////////////////////////
48 integer wasListCountExclude(list input, list exclude) {
49 if(llGetListLength(input) == 0) return 0;
50 if(llListFindList(exclude, (list)llList2String(input, 0)) == -1)
51 return 1 + wasListCountExclude(llDeleteSubList(input, 0, 0), exclude);
52 return wasListCountExclude(llDeleteSubList(input, 0, 0), exclude);
53 }
54  
55 // corrade data
56 string CORRADE = "";
57 string GROUP = "";
58 string PASSWORD = "";
59 list BUTTONS = [];
60  
61 // for notecard reading
62 integer line = 0;
63  
64 // key-value data will be read into this list
65 list tuples = [];
66  
67 default {
68 state_entry() {
69 // DEBUG
70 llSetText("Dialog harness: touch to\n send dialog to Corrade.", <1,1,1>, 1.0);
71 if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) {
72 llOwnerSay("Sorry, could not find a configuration inventory notecard.");
73 return;
74 }
75 // DEBUG
76 llOwnerSay("Reading configuration file...");
77 llGetNotecardLine("configuration", line);
78 }
79 dataserver(key id, string data) {
80 if(data == EOF) {
81 // invariant, length(tuples) % 2 == 0
82 if(llGetListLength(tuples) % 2 != 0) {
83 llOwnerSay("Error in configuration notecard.");
84 return;
85 }
86 CORRADE = llList2String(
87 tuples,
88 llListFindList(
89 tuples,
90 [
91 "corrade"
92 ]
93 )
94 +1);
95 if(CORRADE == "") {
96 llOwnerSay("Error in configuration notecard: corrade");
97 return;
98 }
99 GROUP = llList2String(
100 tuples,
101 llListFindList(
102 tuples,
103 [
104 "group"
105 ]
106 )
107 +1);
108 if(GROUP == "") {
109 llOwnerSay("Error in configuration notecard: password");
110 return;
111 }
112 PASSWORD = llList2String(
113 tuples,
114 llListFindList(
115 tuples,
116 [
117 "password"
118 ]
119 )
120 +1);
121 if(PASSWORD == "") {
122 llOwnerSay("Error in configuration notecard: password");
123 return;
124 }
125 BUTTONS = llCSV2List(
126 llList2String(
127 tuples,
128 llListFindList(
129 tuples,
130 [
131 "buttons"
132 ]
133 )
134 +1)
135 );
136 if(llGetListLength(BUTTONS) == 0) {
137 llOwnerSay("Error in configuration notecard: buttons");
138 return;
139 }
140 // DEBUG
141 llOwnerSay("Read configuration notecard...");
142 state dialog;
143 }
144 if(data == "") jump continue;
145 integer i = llSubStringIndex(data, "#");
146 if(i != -1) data = llDeleteSubString(data, i, -1);
147 list o = llParseString2List(data, ["="], []);
148 // get rid of starting and ending quotes
149 string k = llDumpList2String(
150 llParseString2List(
151 llStringTrim(
152 llList2String(
153 o,
154  
155 ),
156 STRING_TRIM),
157 ["\""], []
158 ), "\"");
159 string v = llDumpList2String(
160 llParseString2List(
161 llStringTrim(
162 llList2String(
163 o,
164 1
165 ),
166 STRING_TRIM),
167 ["\""], []
168 ), "\"");
169 if(k == "" || v == "") jump continue;
170 tuples += k;
171 tuples += v;
172 @continue;
173 llGetNotecardLine("configuration", ++line);
174 }
175 on_rez(integer num) {
176 llResetScript();
177 }
178 changed(integer change) {
179 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
180 llResetScript();
181 }
182 }
183 }
184  
185 state dialog {
186 state_entry() {
187 // DEBUG
188 llOwnerSay("Touch to send dialog to Corrade...");
189 }
190 touch_start(integer num) {
191 integer channel = -(integer)llFrand(100)-1;
192 llListen(channel, "", (key)CORRADE, "");
193 // DEBUG
194 llOwnerSay("Sending dialog...");
195 llDialog((key)CORRADE, "Please select from the options below: ", BUTTONS, channel);
196 }
197 listen(integer channel, string name, key id, string message) {
198 llOwnerSay("Corrade pressed button: " + message);
199 }
200 on_rez(integer num) {
201 llResetScript();
202 }
203 changed(integer change) {
204 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
205 llResetScript();
206 }
207 }
208 }