I know how to do a lot of this, in terms of notecards, lists, etc but where it comes to storing large numbers of infromation, I'm stuck.. let me throw out some mystical pseudocode, and we'll see what it looks like. This will very likely NOT compile, and iif it does, it won't do squat.. but hopefully it will help some of you understand.
CODE
integer menuHandle;
integer menuChan = 37829;
default
{
touch_start(integer numdetected)
{
llListenRemove(menuHandle);
menuHandle = llListen(menuChan, "", llDetectedKey(0), "");
llGiveDialog(llDetectedKey(0), "Pick one", ["Join", "Leave"], menuChan);
}
listen(integer channel, string name, key id, string message)
{
if (channel == menuChan)
{
llListenRemove(menuHandle);
if (message == "Join") newsletterUUIDs(id, TRUE);
else if (message == "Leave") newsletterUUIDs(id, FALSE);
}
}
}
Now.. the basic elements of the menuing system established, you can see that we're going to pass a user's UUID and a TRUE/FALSE integer to a function.
Now, that function would, in some universe, send a message to a php script existing someplace else. (on a webserver). let's assume for argument's sake that the function looked something like this.
CODE
key HTTPRequestID ;
newsletterUUIDs (key id, integer add)
{
if (add)
{
HTTPRequestID = llHTTPRequest("http://www.mysite.com/newsletter.php?UUID="
+ (string)id + "&command=add", [], "");
}
else // remove
{
HTTPRequestID = llHTTPRequest("http://www.mysite.com/newsletter.php?UUID="
+ (string)id + "&command=rem", [], "");
}
}
now, newsletter.php
If the command is "add", newsletter.php's job is to search through a list of UUIDs it has stored, and see if the "new" UUID is present. If it's new, the script should append the UUID to the end of the list. If it's already present in the list, it should probably just do nothing.
If the command is "rem", newsletter.php again searches the existing list, and if it finds the UUID in question, it should remove it from the list. If it's not there, it shouldn't do anything.
Returned messages would look like " removed" or "not found" or "added", or "already present"... basic stuff. The script could then "say" these responses into local chat, or display them in temporary hovertext.. it really doesn't matter.
So this is basic in and out list stuff... here comes the hard part.
Script number two.
CODE
string notecard;
default
{
changed (integer change)
{
if (change & CHANGED_INVENTORY)
{
if (llGetInventoryNumber(INVENTORY_NOTECARD) > 0)
{
notecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
sendNewsletter();
}
else notecard = "";
}
}
}
As you can see, this script so far is just joing to send out a notecard, any time that a notecard is dropped on it. The contents of the mystical sendNewsletter function are a bit of a mystery to me.. but here's my best try at what THAT might look like.
CODE
integer totalLines;
key HTTPRequestID ;
integer count = 0;
sendNewsletter()
{
HTTPRequestID = llHTTPRequest("http://www.mysite.com/newsletter.php?UUID="
+ (string)llGetOwner() + "&command=tot", [], "");
}
then we'd need a special sort of response from the script, in the http_response event.. something like "tot|378"
CODE
http_response(key id, integer status, list meta, string body)
{
list commands = llParseString2List(body, ["|"], []);
if (llList2String(commands, 0) == "tot")
{
totalLines = (integer)llList2String(commands, 1);
HTTPRequestID = llHTTPRequest("http://www.mysite.com/newsletter.php?UUID="
+ (string)llGetOwner() + "&command=get&number=" + (string)count, [], "");
}
}
Now the heart of it all. Someplace in all of this, we need to ask the newsletter.php script to give up it's gold. In this case, we probably want to do something like this. We'll use the response token "uuid" (uuid|blahblah-blah-blah-blahblahblah)
CODE
http_response(key id, integer status, list meta, string body)
{
list commands = llParseString2List(body, ["|"], []);
if (llList2String(commands, 0) == "uuid")
{
llGiveInventory((key)llList2String(commands, 1), notecard);
count += 1;
HTTPRequestID = llHTTPRequest("http://www.mysite.com/newsletter.php?UUID="
+ (string)llGetOwner() + "&command=get&number=" + (string)count, [], "");
}
}
Now, all the basic LSL elements are here. The formatting isn't 100% perfect, and obviously it could use a little error handling and noob proofing.. that's all great, but you can see the basics of how this would work.
Script A handles add and remove requests, and passes them to the php script for handling.
Script B waits til it's handed a notecard, and then it asks the php scripts how many UUIDs are on file, and then goes one by one, asking the script for a UUID, then sending out the notecard, asking for the next UUID, handing them a notecard, again and again until the whole list is finished.
I figure at that point, the lsl script receives some sort of EOF in commands 0..
CODE
http_response(key id, integer status, list meta, string body)
{
list commands = llParseString2List(body, ["|"], []);
if (llList2String(commands, 0) == "eof")
{
llRemoveInventory(notecard);
}
}
It can do all sorts of fancy cleanups at that point, or just reset the script. The particulars of the thing aren't so important.
The problem is, I'm missing the PHP side of this thing. Now it could just as easily be a perl/cgi script handling these tasks. It could be using an sql database, or it could just be creating a comma deliniated list of keys in a single "newsletter.txt" file.
But that part is beyond me.
Anyone care to lend a hand?