corrade-lsl-templates – Diff between revs 11 and 15
?pathlinks?
Rev 11 | Rev 15 | |||
---|---|---|---|---|
Line 168... | Line 168... | |||
168 | // store message over state. |
168 | // store message over state. |
|
169 | string data = ""; |
169 | string data = ""; |
|
Line 170... | Line 170... | |||
170 | |
170 | |
|
171 | // Notecard reading. |
171 | // Notecard reading. |
|
172 | key nQuery = NULL_KEY; |
172 | key nQuery = NULL_KEY; |
|
173 | integer nLine = 0; |
173 | string joke = ""; |
|
- | 174 | list q = [ ]; |
||
- | 175 | |
||
- | 176 | /////////////////////////////////////////////////////////////////////////// |
||
- | 177 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
||
- | 178 | /////////////////////////////////////////////////////////////////////////// |
||
- | 179 | // Requires: a limit. |
||
- | 180 | // Provides: true random number between [0, max) or (-max, 0]. |
||
- | 181 | ////////////////////////////////////////////////////////// |
||
- | 182 | integer wasFPSrand(integer max) { |
||
- | 183 | integer r = (integer)(llGetRegionFPS() * 10000000.0) % max; |
||
- | 184 | if(max > 0) return r; else return -r; |
||
Line 174... | Line 185... | |||
174 | list nList = []; |
185 | } |
|
175 | |
186 | |
|
176 | default { |
187 | default { |
|
177 | state_entry() { |
188 | state_entry() { |
|
178 | llOwnerSay("[Joke] Starting module..."); |
189 | llOwnerSay("[Joke] Starting module..."); |
|
179 | llSetTimerEvent(10); |
190 | llSetTimerEvent(10); |
|
180 | } |
191 | } |
|
181 | link_message(integer sender, integer num, string message, key id) { |
192 | link_message(integer sender, integer num, string message, key id) { |
|
182 | if(id != "configuration") return; |
193 | if(id != "configuration") return; |
|
183 | llOwnerSay("[Joke] Got configuration..."); |
194 | llOwnerSay("[Joke] Got configuration..."); |
|
184 | configuration = message; |
195 | configuration = message; |
|
185 | state read_jokes; |
196 | state count_jokes; |
|
186 | } |
197 | } |
|
187 | timer() { |
198 | timer() { |
|
188 | llOwnerSay("[Joke] Requesting configuration..."); |
199 | llOwnerSay("[Joke] Requesting configuration..."); |
|
Line 201... | Line 212... | |||
201 | state_exit() { |
212 | state_exit() { |
|
202 | llSetTimerEvent(0); |
213 | llSetTimerEvent(0); |
|
203 | } |
214 | } |
|
204 | } |
215 | } |
|
Line 205... | Line 216... | |||
205 | |
216 | |
|
206 | state read_jokes { |
217 | state count_jokes { |
|
- | 218 | state_entry() { |
||
- | 219 | // Build a list of dataserver queries and retrieve the number of lines. |
||
- | 220 | joke = (string)llGetInventoryNumber(INVENTORY_NOTECARD); |
||
207 | state_entry() { |
221 | integer i = (integer)joke - 1; |
|
208 | // DEBUG |
222 | do { |
|
209 | llOwnerSay("[Joke] Reading jokes..."); |
223 | string card = llGetInventoryName(INVENTORY_NOTECARD, i); |
|
210 | if(llGetInventoryType("Joke") != INVENTORY_NOTECARD) { |
224 | // Filter notecards containing the "jokes" configuration key value. |
|
- | 225 | if(llSubStringIndex(card, wasKeyValueGet("jokes", configuration)) == -1) { |
||
211 | llOwnerSay("[Joke] Failed to find a notecard named Joke in the primitive's inventory."); |
226 | joke = (string)((integer)joke - 1); |
|
212 | return; |
227 | jump continue; |
|
213 | } |
228 | } |
|
- | 229 | q = llListInsertList(q, [ llGetNumberOfNotecardLines(card) ], 0); |
||
- | 230 | @continue; |
||
- | 231 | } while(--i >= -1); |
||
214 | nQuery = llGetNotecardLine("Joke", nLine); |
232 | q += NULL_KEY; |
|
215 | } |
233 | } |
|
216 | dataserver(key id, string data) { |
234 | dataserver(key id, string data) { |
|
217 | if(id != nQuery) return; |
235 | // Find the query in the query list. |
|
218 | if(data == EOF) { |
236 | integer i = llListFindList(q, [ id ]); |
|
- | 237 | if(i == -1) return; |
||
- | 238 | |
||
- | 239 | // Replace the query by the number of notecard lines (lists are covariant). |
||
219 | // DEBUG |
240 | q = llListReplaceList(q, [ (integer) data ], i, i); |
|
- | 241 | joke = (string)((integer)joke - 1); |
||
220 | llOwnerSay("[Joke] Read jokes..."); |
242 | if((integer)joke == 0) |
|
221 | state listen_group; |
243 | state listen_group; |
|
222 | } |
- | ||
223 | if(data == "") jump continue; |
- | ||
224 | nList += data; |
- | ||
225 | @continue; |
- | ||
226 | nQuery = llGetNotecardLine("Joke", ++nLine); |
- | ||
227 | } |
244 | } |
|
228 | on_rez(integer num) { |
245 | on_rez(integer num) { |
|
229 | llResetScript(); |
246 | llResetScript(); |
|
230 | } |
247 | } |
|
231 | changed(integer change) { |
248 | changed(integer change) { |
|
Line 263... | Line 280... | |||
263 | if(llGetSubString(data, 0, 0) != |
280 | if(llGetSubString(data, 0, 0) != |
|
264 | wasKeyValueGet("command", configuration)) |
281 | wasKeyValueGet("command", configuration)) |
|
265 | return; |
282 | return; |
|
Line 266... | Line 283... | |||
266 | |
283 | |
|
267 | // Check if the command matches the current module. |
284 | // Check if the command matches the current module. |
|
268 | list command = llParseString2List(data, |
285 | list command = llParseString2List(data, [" "], []); |
|
269 | [wasKeyValueGet("command", configuration), " "], ["@"]); |
286 | if(llList2String(command, 0) != |
|
270 | if(llList2String(command, 0) != "joke") |
287 | wasKeyValueGet("command", configuration) + "joke") |
|
Line 271... | Line 288... | |||
271 | return; |
288 | return; |
|
272 | |
289 | |
|
273 | list range = wasCSVToList( |
- | ||
Line -... | Line 290... | |||
- | 290 | // Remove command. |
||
- | 291 | command = llDeleteSubList(command, 0, 0); |
||
- | 292 | |
||
- | 293 | state read_joke; |
||
- | 294 | } |
||
- | 295 | on_rez(integer num) { |
||
- | 296 | llResetScript(); |
||
- | 297 | } |
||
- | 298 | changed(integer change) { |
||
274 | wasKeyValueGet("roll range", configuration) |
299 | if((change & CHANGED_INVENTORY) || |
|
- | 300 | (change & CHANGED_REGION_START) || |
||
- | 301 | (change & CHANGED_OWNER)) { |
||
- | 302 | llResetScript(); |
||
- | 303 | } |
||
- | 304 | } |
||
- | 305 | } |
||
- | 306 | |
||
- | 307 | state read_joke { |
||
- | 308 | state_entry() { |
||
- | 309 | // DEBUG |
||
- | 310 | llOwnerSay("[Joke] Reading a joke..."); |
||
- | 311 | |
||
- | 312 | integer i = llGetInventoryNumber(INVENTORY_NOTECARD) - 1; |
||
- | 313 | list c = []; |
||
- | 314 | do { |
||
- | 315 | string card = llGetInventoryName(INVENTORY_NOTECARD, i); |
||
- | 316 | if(llSubStringIndex(card, wasKeyValueGet("jokes", configuration)) == -1) |
||
- | 317 | jump continue; |
||
- | 318 | c = llListInsertList(c, [ i ], 0); |
||
- | 319 | @continue; |
||
- | 320 | } while(--i >= -1); |
||
- | 321 | |
||
- | 322 | i = (integer)llFrand(llGetListLength(c)); |
||
- | 323 | nQuery = llGetNotecardLine( |
||
275 | ); |
324 | llGetInventoryName( |
|
276 | |
325 | INVENTORY_NOTECARD, |
|
- | 326 | llList2Integer(c, i) |
||
277 | data = llList2String( |
327 | ), |
|
278 | nList, |
328 | (integer) |
|
- | 329 | ( |
||
- | 330 | llFrand( |
||
- | 331 | llList2Integer( |
||
- | 332 | q, |
||
279 | (integer) |
333 | i |
|
280 | llFrand( |
334 | ) |
|
281 | llGetListLength(nList) |
335 | ) |
|
- | 336 | ) |
||
- | 337 | ); |
||
- | 338 | } |
||
282 | ) |
339 | dataserver(key id, string data) { |
|
283 | ); |
340 | if(id != nQuery) return; |
|
284 | |
341 | joke = data; |
|
285 | state tell; |
342 | state tell; |
|
286 | } |
343 | } |
|
Line 319... | Line 376... | |||
319 | "password", |
376 | "password", |
|
320 | configuration |
377 | configuration |
|
321 | ) |
378 | ) |
|
322 | ), |
379 | ), |
|
323 | "entity", "group", |
380 | "entity", "group", |
|
324 | "message", wasURLEscape(data) |
381 | "message", wasURLEscape(joke) |
|
325 | ] |
382 | ] |
|
326 | ) |
383 | ) |
|
327 | ); |
384 | ); |
|
- | 385 | |
||
- | 386 | // GC |
||
- | 387 | joke = ""; |
||
- | 388 | |
||
328 | state listen_group; |
389 | state listen_group; |
|
329 | } |
390 | } |
|
330 | } |
391 | } |