Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Notecard Config Files

Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
11-17-2007 05:59
Hi guys!

I'm wanting to create a simple config file on a notecard for some of my scripts. I've been using notecards to read in CSV information from notecards for a while now but I want something a little easier for an end user to edit, something that would look something like this:

var1 = param1
var2 = param2

I did think about doing it with CSV again but in the past I've found people get confused about how it works. I was thinking something like

var1 = "param1"
var2 = "param2"

might be an easy way to deal with any spaces that the end user may put in a parameter, not sure.

Any advice?
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
11-17-2007 06:07
The quotes shouldn't be necessary, as the card data will be read as a string anyway, one line at a time. Parse out everything before the = sign to determine what variable is being defined, and everything after to determine the value. Typecast as necessary.
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
11-17-2007 06:13
OK, thanks, I think I get what you're saying. I've never done what you're suggesting in LSL though, only PHP so I'll have to have a look at the wiki. I assume there's some kind of function to split the string at a defined character (ie = in this case?)
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
11-17-2007 06:27
Along with what Deanna suggested, I would also strip trailing spaces off the variable name, and leading and trailing spaces off the param - if it's to be treated as string data, I would keep any internal spaces. llStringTrim will do that for you.
_____________________
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
11-17-2007 07:32
Brilliant, thanks Stephen, I've just been looking for that function and couldn't find it! Thanks to both of you
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
11-17-2007 07:37
From: Landing Normandy
I assume there's some kind of function to split the string at a defined character (ie = in this case?)
Use llSubStringIndex to find the specified character, then use that value in llGetSubString or llDeleteSubString. The way I'd do it, inside dataserver, after appropriate QID and EOF checks:

integer sep = llSubStringIndex( data, "=" ); // separator index
string varname = llDeleteSubString( data, sep, -1 ); // strips off the = and everything after
string value = llDeleteSubString( data, 0, sep ); // strips off the = and everything before

That's the simple version. To be sure, further enclose the llDeleteSubString calls in llStringTrim, to remove any leading and trailing spaces, and llToLower on the varname assignment, to account for CAPS in the notecard.

Or, you can use llParseString2List, which would ( *should* ) result in a 2 element list, the first of which is the varname, the second is the value. But a list containing 2 strings takes up more memory than 2 strings and an integer, if mem efficiency is an issue. llStringTrim and llToLower notes still apply.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-17-2007 16:56
to extend what deanna said, remember to typecast any variables that will not be a string, and if the a string is not being used externally, use llToLower, or llToUpper on it as well to simplify internal comparisons, including command line parsing....
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -