Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: AdvnacedNotecardReader

Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
08-25-2008 11:17
This code is a robust notecard reader that reads all notecards with a given substring in the name, and saves configuration to global variables. Doesn't require any resets. Rereads config on inventory change (but of course, this is controllable by the user code). Includes important best practices that are omitted from other examples, including:

- resetting config to defaults in a function, eschewing assignments at declarations, to provide reliable behavior on reconfig when configuration lines were deleted.
- support for error messages giving notecard name and line number
- handling nonreply by server using timeout, rather than getting wedged requiring reset
- examples to add config items to global lists (example -- trivial but helpful to many)
- debug support

Details at http://wiki.secondlife.com/wiki/AdvancedNotecardReader.

Feedback please, before I submit a thread to Scripting Library. If this isn't the best way to do this, just let me know. :)

On inspecting the code while posting, I noticed that it uses an unnecessary list to hold the config card names. I'll optimize that when I get the chance to compile and test inworld.

This is code used successfully since early 2007 in very popular products. I have not had a customer support issue regarding it. Still, no doubt there are bugs and improvements, so please add your two cents.

In practice, I usually put the init routine directly below the declarations of the config variables, so that I remember to initialize them when adding a new one. Do you think it would be confusing to do that in the posted version?
Core Taurog
Registered User
Join date: 2 May 2007
Posts: 17
08-25-2008 21:59
Just a minor thing; might be worth changing the "config_parse" method to
CODE

if (cmd == "foo")
{
// do stuff
return;
}
if (cmd == "bar")
{
// do something else
return;
}


or at least mention the limit of the number of "else if" clauses in the comments somewhere; it's really easy to hit the limit when parsing things in this way, and it seems you've tried to be quite newbie friendly here - the errors you get for breaking these limits are un-useful.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
08-26-2008 08:11
It'd add a bunch of complexity and eat more memory but saving the keys of the notecards you've read would allow the changed event to see if a config has actually been changed.

Right now, you'll reparse any time a script gets recompiled or somebody drops a texture into the object or anything like that. I think there at least used to be a bug where even opening a notecard would trigger changed.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
08-26-2008 09:16
From: Core Taurog
Just a minor thing; might be worth changing the "config_parse" method to
CODE

if (cmd == "foo")
{
// do stuff
return;
}
if (cmd == "bar")
{
// do something else
return;
}


or at least mention the limit of the number of "else if" clauses in the comments somewhere; it's really easy to hit the limit when parsing things in this way, and it seems you've tried to be quite newbie friendly here - the errors you get for breaking these limits are un-useful.


Good point, I'll change the code or mention that.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
08-26-2008 09:23
From: Meade Paravane
It'd add a bunch of complexity and eat more memory but saving the keys of the notecards you've read would allow the changed event to see if a config has actually been changed.
Interesting idea! I'll mention that, and perhaps add supporting code as comments. Gee, I find myself almost wishing for #ifdefs in LSL!

From: someone
Right now, you'll reparse any time a script gets recompiled or somebody drops a texture into the object or anything like that.
For most objects where I've used this, it's fine to have an extra config read now and then. For objects with lots of other content (e.g., MLPV2), I omitted initiating a reconfig in "change" handlers in the working state, because it would be terrible to reconfigure on every anim add or delete. In this case, I feel it's best for reconfig to be explicit and not automatic -- unless you have the memory available for holding the notecard UUIDs.

I'll add some text to make that clearer (it's already mentioned in some comments).

Thanks!
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
08-26-2008 09:27
I also avoided the optimization for "mylist += (list)myitem", for saving memory. Let me know whether you think that belongs in the example code or not.

I left it out for clarity, but it might be better to have it in. Anyone know whether it works the same way in Mono?