Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dataserver madness

Denrael Leandros
90 Degrees From Everythin
Join date: 21 May 2005
Posts: 103
08-28-2006 15:46
I have the following block of code...

// Configuration Notecard Information
string PLAYLIST = "Playlist";
string CONFIG = "Config";
integer DEBUG = 1;
integer gConfigLineNbr = 0;
key gConfigKey = "";
list gUserList = [];
list gLimitedUserList = [];
string gConfigBlock = "";


Initialize() {
gConfigKey = llGetNotecardLine(CONFIG, gConfigLineNbr);
}

default {
state_entry() {
Initialize();
}

dataserver(key queryid, string data) {
if (gConfigKey == queryid) {
if (data != EOF) {
if (llGetSubString(data, 0, 0) == "[";) {
gConfigBlock = data;
} else if (gConfigBlock = "[USERS]";) {
gUserList += data;
} else if (gConfigBlock = "[LIMITED USERS]";) {
gLimitedUserList += data;
}
if (DEBUG) {
llSay(0,"data";);
llSay(0,data);
llSay(0,"gConfigBlock";);
llSay(0,gConfigBlock);
llSay(0,"gUserList";);
llSay(0,llList2CSV(gUserList));
llSay(0,"gLimitedUserList";);
llSay(0,llList2CSV(gLimitedUserList));
}
gConfigLineNbr++;
gConfigKey = llGetNotecardLine(CONFIG, gConfigLineNbr);
}
}
}
}


And the following data files...

===Start of file===
[USERS]
Bob
Ted
[LIMITED USERS]
Carol
===End of file===

With the debug statements, I get the following output:


[15:45] Object: data
[15:45] Object: [USERS]
[15:45] Object: gConfigBlock
[15:45] Object: [USERS]
[15:45] Object: gUserList
[15:45] Object:
[15:45] Object: gLimitedUserList
[15:45] Object:
[15:45] Object: data
[15:45] Object: Bob
[15:45] Object: gConfigBlock
[15:45] Object: [USERS]
[15:45] Object: gUserList
[15:45] Object: Bob
[15:45] Object: gLimitedUserList
[15:45] Object:
[15:45] Object: data
[15:45] Object: Ted
[15:45] Object: gConfigBlock
[15:45] Object: [USERS]
[15:45] Object: gUserList
[15:45] Object: Bob, Ted
[15:45] Object: gLimitedUserList
[15:45] Object:
[15:45] Object: data
[15:45] Object: [LIMITED USERS]
[15:45] Object: gConfigBlock
[15:45] Object: [LIMITED USERS]
[15:45] Object: gUserList
[15:45] Object: Bob, Ted
[15:45] Object: gLimitedUserList
[15:45] Object:
[15:45] Object: data
[15:45] Object: Carol
[15:45] Object: gConfigBlock
[15:45] Object: [USERS]
[15:45] Object: gUserList
[15:45] Object: Bob, Ted, Carol
[15:45] Object: gLimitedUserList
[15:45] Object:

For some reason, my variable gConfigBlock is being reset to [USERS] it appears, and all names appear in that list. I'm totally confused as to why this is happening!

HELP!
Thanks
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
08-28-2006 16:01
Argh. Please use the [ PHP ] tags when posting code, every reader on this forum will thank you :)

And your bug: you need == for comparison. You're using single = in the two if() checks for gConfigBlock. From the rest of your code, you look like you know what you're doing, so this is probably a typo. Feel free to spend a few minutes kicking yourself :)
Denrael Leandros
90 Degrees From Everythin
Join date: 21 May 2005
Posts: 103
08-28-2006 16:04
Kick Kick Kick Kick Kick Kick!

I swear I examined that code for 2 hours before I gave the cry!
Thanks.

I'll figure out the PHP tags, sorry

From: Ziggy Puff
Argh. Please use the [ PHP ] tags when posting code, every reader on this forum will thank you :)

And your bug: you need == for comparison. You're using single = in the two if() checks for gConfigBlock. From the rest of your code, you look like you know what you're doing, so this is probably a typo. Feel free to spend a few minutes kicking yourself :)
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
08-28-2006 18:40
just so you know you can look up any of the "vb" codes with the link @ the bottom of the page

or so you dont have to look ...
http://forums.secondlife.com/misc.php?do=bbcode
Bosozoku Kato
insurrectionist midget
Join date: 16 Jun 2003
Posts: 452
08-29-2006 01:58
You'll get more names (as incoming 'data') than "config blocks" I'd do the process more like so...

CODE
dataserver(key queryid, string data)
{
if (gConfigKey == queryid)
{
if (data != EOF && llStringLength(data) > 0) // I just don't like processing blank lines :)
{
if (llGetSubString(data, 0, 0) != "[") // if it's NOT a config block...
{
if (gConfigBlock == "[USERS]")
{
gUserList += data;
}
else // else it's limited (else use more "else if" checks if you add more categories
{
gLimitedUserList += data;
}
}
else // it is a config block
{
gConfigBlock = data;
}
}
}
}


sorry php quote doesn't like my use of tab/spaces and copy/paste from notepad -- and I'm too lazy to clean it up.
_____________________
float llGetAFreakingRealTimeStampSince00:00:00Jan11970();
Marcuw Schnook
Scripter
Join date: 24 Dec 2005
Posts: 246
08-29-2006 03:47
From: Denrael Leandros
I
} else if (gConfigBlock = "[USERS]";) {
gUserList += data;
} else if (gConfigBlock = "[LIMITED USERS]";) {


Snipped...

Take a carefull look!
you assign gConfigBlock with the value = "[USERS]" and that evaluates to TRUE.

Try for a change:

} else if ("[USERS]" = gConfigBlock ) {
gUserList += data;
} else if ("[LIMITED USERS]" = gConfigBlock) {

That will give you a compiler error: you cannot assign a variable to a constant value.

What you WANT is:
} else if ("[USERS]" == gConfigBlock ) {
gUserList += data;
} else if ("[LIMITED USERS]" == gConfigBlock) {

I make it a bit bigger, because a lot of people seem to miss this all the time.

The trick: use <value> expression <variable> to allow parser to catch errors
Denrael Leandros
90 Degrees From Everythin
Join date: 21 May 2005
Posts: 103
08-29-2006 22:42
Thanks to all of you for taking the time in showing me the obvious right before my eyes. I do apprecaite the community out here.