Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

problem with notecard configuration/ llCSV2List

psimagus Hax
Registered User
Join date: 3 Jul 2007
Posts: 73
05-28-2008 10:22
I've hit an infuriating block (doubtless I'm misunderstanding some fundamental of the way llCSV2List is supposed to work,) and I wonder if anyone could tell me what I'm doing wrong here?
It's a script to load up a configuration from a notecard, and the settings that are stored as strings (EMAIL, ACCESS, STAMPS) work fine - the strings hold their values and are usable later in the script. But when I attempt to populate 3 lists using llCSV2List (and I've tried LlParseString2List too with similar lack of success,) the lists don't seem to hold their contents. I can return any particular entry (or indeed the whole list,) immediately after the llCSV2List, but by the time it gets to state_exit(), the lists are unaccountably empty again.

Weird huh? Or am I being dim again? (I certainly can't rule that out! :O)

TIA for any clues!




"settings" NOTECARD CONTAINING LINES:


email = none
access = public
timestamp = on
init_messages = "This is a test!,This is a second test!,third test message,Test No.4!"
init_names = "Joe Bloggs,psimagus Hax,John Doe,George Bush"
init_timestamps = "2008-05-18 @ 13:16:50,2008-05-22 @ 11:34:11,2008-05-27 @ 18:26:30,2008-05-28 @ 19:15:21"


SCRIPT:

integer totalnumber;
string avname;
string currentname;
string message;
list messageList; // list containing messages, each definable by 'position'
list avList; // which should match the 'position' of each name in this list
list timestamps; // and timestamps since they're incremented in the same code block

string CONFIG_CARD = "settings";
string EMAIL = "none";
string ACCESS = "public";
string STAMPS = "off";
integer NotecardLine;
key QueryID;


default
{
state_entry()
{

llOwnerSay("Initializing...";);

if (llGetInventoryType(CONFIG_CARD) == INVENTORY_NOTECARD)
{
NotecardLine = 0;
QueryID = llGetNotecardLine( CONFIG_CARD, NotecardLine );
}
else
{
llOwnerSay("Configuration notecard missing, using defaults.";);
state Running;
}
}


dataserver( key queryid, string data )
{
list temp;
string name;
string value;

if ( queryid == QueryID )
{
if ( data != EOF )
{
if ( llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "" )
{
temp = llParseString2List(data, ["="], []);
name = llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM);
value = llStringTrim(llList2String(temp, 1), STRING_TRIM);

if ( name == "email" )
{
EMAIL = (string)value;
}
else if ( name == "access" )
{
ACCESS = (string)value;
}
else if ( name == "timestamp" )
{
STAMPS = (string)value;
}
else if ( name == "initmessages" )
{
list messageList = llCSV2List(value);
integer totalnumber = (llGetListLength(messageList));
llOwnerSay("Default message queue loaded - " + (string)totalnumber + " messages.";);

llSay(0, llList2String(messageList,0)); //
llSay(0, llList2String(messageList,1)); // TEST TO ENSURE CSV2List WORKING
llSay(0, llList2String(messageList,2)); //
llSay(0, llList2String(messageList,3)); // THESE ALL WORK FINE HERE

}
else if ( name == "initnames" )
{
list avList = llCSV2List(value);

llSay(0, llList2String(avList,0)); //
llSay(0, llList2String(avList,1)); // TEST TO ENSURE CSV2List WORKING
llSay(0, llList2String(avList,2)); //
llSay(0, llList2String(avList,3)); // THESE ALL WORK FINE HERE
}
else if ( name == "inittimestamps" )
{
list timestamps = llCSV2List(value);

llSay(0, llList2String(timestamps,0)); //
llSay(0, llList2String(timestamps,1)); // TEST TO ENSURE CSV2List WORKING
llSay(0, llList2String(timestamps,2)); //
llSay(0, llList2String(timestamps,3)); // THESE ALL WORK FINE HERE
}

}
NotecardLine++;
QueryID = llGetNotecardLine( CONFIG_CARD, NotecardLine );
}
else
{
state Running;
}
}
}

state_exit()
{
llOwnerSay("Email set to: " + (string)EMAIL); //
llOwnerSay("Access set to: " + (string)ACCESS); // THESE WORK FINE
llOwnerSay("Timestamps " + (string)STAMPS); //
llOwnerSay("Initialization Complete!";);



llOwnerSay (llList2String(messageList,1) + " - (" + llList2String(avList,1) + ", " + llList2String(timestamps,1) + ";)";); // TEST TO CHECK MATCHING A RANDOM MATCHING RECORD FROM EACH LIST - THIS DOESN'T WORK :(

llSay(0, llList2String(messageList,0)); //
llSay(0, llList2String(avList,1)); // NEITHER DO THESE - THE LISTS ARE EMPTY :(
llSay(0, llList2String(timestamps,2)); //
}
}
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
05-28-2008 10:30
You are declaring timestamps and avList twice each, first as a globals and then inside your event. That makes them separate, and that's not what you want, is it?
_____________________
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
05-28-2008 10:38
Didn't look too closely at this but you're using the same variable name for both a global variable and a local variable..

This is (no offense!) an excellent demonstration of why it's a good idea to have a consistent naming convention for variables in scripts. I don't care what convention you use but you really should use one - it'll avoid problems like you're seeing and make your code easier to read. See also: http://forums.secondlife.com/showpost.php?p=1998138&postcount=9

CODE

integer totalnumber;
string avname;
string currentname;
string message;
list messageList; // list containing messages, each definable by 'position'
list avList; // which should match the 'position' of each name in this list
list timestamps; // and timestamps since they're incremented in the same code block

string CONFIG_CARD = "settings";
string EMAIL = "none";
string ACCESS = "public";
string STAMPS = "off";
integer NotecardLine;
key QueryID;
.
.
.
else if ( name == "initnames" )
{
list avList = llCSV2List(value);
.
.
_____________________
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
psimagus Hax
Registered User
Join date: 3 Jul 2007
Posts: 73
05-28-2008 12:47
From: Meade Paravane
Didn't look too closely at this but you're using the same variable name for both a global variable and a local variable..

This is (no offense!)


Fear not! I am happy to take any and all offence upon myself (I have almost no idea what I'm doing, flailing around in a great soup of code! :))

From: Meade Paravane
an excellent demonstration of why it's a good idea to have a consistent naming convention for variables in scripts. I don't care what convention you use but you really should use one - it'll avoid problems like you're seeing and make your code easier to read. See also: /54/8e/260376/1.html#post1998138

CODE

integer totalnumber;
string avname;
string currentname;
string message;
list messageList; // list containing messages, each definable by 'position'
list avList; // which should match the 'position' of each name in this list
list timestamps; // and timestamps since they're incremented in the same code block

string CONFIG_CARD = "settings";
string EMAIL = "none";
string ACCESS = "public";
string STAMPS = "off";
integer NotecardLine;
key QueryID;
.
.
.
else if ( name == "initnames" )
{
list avList = llCSV2List(value);
.
.



I can't quite get my head around that, and I confess - php just scares me (I'm hoping the php headers in your quote are just an artefact of the 'response process', or you've *really* got me worried now!)
If I've declared the same variable twice (locally and globally), I can't help wondering why, when I comment out the initial declaration of the 3 strings, I get an error telling me that the (what I am forced to conclude are necessary) variables are "not defined within scope"?
Like - all of the above in the basic script, except when I add some slashes, viz:

// list messageList;
// list avList;
// list timestamps;

I get self-important errors telling me I've failed to declare variables. So these seem to be the critical declarations (if, without them, it all grinds to a halt!) But how then do I specify any content for these lists? I assume they have to be declared blank? Or is there some way to make it listen for lines from a notecard before it even enters (state_)default?

I guess what I want to know (in my dim and groping newbie-sense consciousness) is how to declare the variable locally without declaring it globally (though I don't guarantee I don't mean the exact opposite, or some random reassembly of the terms. Ow! Now my head just hurts :()


--
I want to believe ^h^h^h^h^h^h^h understand - I'd just like to know what I was doing more ^h^h^h^h ANY of the time (and whether it was making anything like headway!)
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
05-28-2008 12:50
_Inside_ your dataserver event, just take out the declaration part ( change 'list avList = blah;' to just 'avList = blah;' ). The globals up top can stay, since that's what you want, for the variables to be visible to the whole script.
_____________________
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
05-28-2008 13:01
From: Viktoria Dovgal
_Inside_ your dataserver event, just take out the declaration part ( change 'list avList = blah;' to just 'avList = blah;' ). The globals up top can stay, since that's what you want, for the variables to be visible to the whole script.

Yep..

Sorry to scare you with the PHP tags, psimagus - if the forum software here ever gets fixed, those tags will make LSL code format nicely. It's got nothing to do with the PHP language.
_____________________
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
psimagus Hax
Registered User
Join date: 3 Jul 2007
Posts: 73
05-28-2008 15:30
From: Viktoria Dovgal

_Inside_ your dataserver event, just take out the declaration part ( change 'list avList = blah;' to just 'avList = blah;' ). The globals up top can stay, since that's what you want, for the variables to be visible to the whole script.


Many thanks - it works! Now I'll try to drum that lesson into my tired brain! I think that underlies another problem too, so 2 for the price of 1 (can't say better than that!)

From: Meade Paravane
Yep..

Sorry to scare you with the PHP tags, psimagus - if the forum software here ever gets fixed, those tags will make LSL code format nicely. It's got nothing to do with the PHP language.


I oughtn't be so scared of it - I've occasionally had to work with php wrappers for javascripts, but I do find myself breaking out in a cold sweat when I see those ominous letters appear in something I want to understand :)