Reading multiple notecards
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-24-2009 22:17
Hi, I am looking for advice on how to approach something. I am reasonbly new to scripting but learning fast and making slow by steady progress... Okay my problem is: I need to have two sperate notecards in a prim. One is an AllowList, the other a config file. I am reading one of the notecards using this code : integer AllowLength = 0; integer CardLine = 0; integer i; key CardDataRead; string CardName; list AllowList;
default { state_entry() { llSay(0, "Hello, Avatar!"); CardName = llGetInventoryName(INVENTORY_NOTECARD, 1); CardDataRead = llGetNotecardLine(CardName, CardLine); } dataserver (key Data_id, string CardData) { if (Data_id == CardDataRead) { if (CardData !=EOF) { AllowList = AllowList + CardData; ++CardLine; CardDataRead = llGetNotecardLine(CardName, CardLine);
} } }
touch_start(integer total_number) { integer len = llGetListLength( AllowList ); for( i = 0; i < len ; i++ ) { llSay(0, llList2String(AllowList, i)); } } }
Now this works fine, as I know that selecting 0 or 1 on the llGetInventoryName command lets me pick which card to read. but I cannot, then tell the script to read the other card and load that data into a seperate list for use in another part of the script. I am wondering how to acutally do this. From my playing it seems I have to have the dataserver commands within "states". So do I need to specify two dummy states and call them to load each card data seperately, or am I looking at this the wrong way? Had I done this in another language I would have just created a startup subroutine and called that at the start to load the notecards (and do anything else needed to setting the program up). But this does not appear to be possible in LSL due to certain commands having to be in certain places it seems. I would welcome some thoughts as to how to approach loading two notecards seperately as I am unsure and pretty lost here to be honest. Thanks Klaire
|
|
missjessie Babii
Crazy Scientist #O_รถ#
Join date: 29 Jul 2008
Posts: 13
|
05-25-2009 00:01
Hello, Use your CardDataRead key as an ID for the request. You have 2 notes : NOTE1, NOTE2. Make 2 keys : CardDataRead1 and CardDataRead2. CardDataRead1 = llGetNotecardLine(NOTE1, CardLine); CardDataRead2 = llGetNotecardLine(NOTE2, CardLine); In the dataserver event : test the key dataserver (key Data_id, string CardData) { if (Data_id == CardDataRead1) { ... } else if (Data_id == CardDataRead2) { ... } } There you can read as many notes as you want making a difference between the requests ^ ^
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-25-2009 00:05
From: missjessie Babii Hello, Use your CardDataRead key as an ID for the request. You have 2 notes : NOTE1, NOTE2. Make 2 keys : CardDataRead1 and CardDataRead2. CardDataRead1 = llGetNotecardLine(NOTE1, CardLine); CardDataRead2 = llGetNotecardLine(NOTE2, CardLine); In the dataserver event : test the key dataserver (key Data_id, string CardData) { if (Data_id == CardDataRead1) { ... } else if (Data_id == CardDataRead2) { ... } } There you can read as many notes as you want making a difference between the requests ^ ^ Omg..... That makes perfect sense and seems really easy too!  Thank you for this MissJessie, I just could not see the answer - it figures it was something simple. Hugs, Klaire
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-25-2009 00:16
or just read them in order...
if (EOF = data) { if (cardname = card1) { cardname = card2 counter = 0 //-get line call else{ //-- next state or variable switch }
ps if you use the first method, be aware you need to track the line numbers separately, and track when they're done separately, etc...
_____________________
| | . "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... | - 
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-25-2009 00:24
From: Void Singer or just read them in order...
if (EOF = data) { if (cardname = card1) { cardname = card2 counter = 0 //-get line call else{ //-- next state or variable switch } Hi Void, This would be after the dataserver command I assume. You are reading card one until you get an EOF error and then telling the routine to swap to card two, and when that gets an EOF it exits the loop - is that right? I am trying to make sure I understand what is happening - rather than just accept it works... Thanks Klaire
|
|
Talon Brown
Slacker Punk
Join date: 17 May 2006
Posts: 352
|
05-25-2009 02:55
This might help you understand a bit better in context, it appears to use the method Void was referring to: http://lslwiki.net/lslwiki/wakka.php?wakka=LibrarySettingsNotecard
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-25-2009 09:27
From: Klaire Larnia Hi Void,
This would be after the dataserver command I assume. You are reading card one until you get an EOF error and then telling the routine to swap to card two, and when that gets an EOF it exits the loop - is that right?
I am trying to make sure I understand what is happening - rather than just accept it works...
Thanks Klaire you got it =) you can also instead of using a single value, use a list which stores (in reverse order) your notecard names to read, and then on EOF search for the current name, if the current file name index as found in the list is positive, store the next name to read as --index, if the index was 0, trigger whatever you need to signal finished reading notecards. something like... if (EOF == data){ integer vIdxNCName = llListFindList( gLstNCNames, (list)gStrNC ); if (vIdxNCName) { gStrNC = llList2String( gLstNCNames, --vIdxNCName ); }else{ //-- done } }
it could be done in forward order, but it simplifies the math/tests to do reverse order because you don't need to check the length of the list to know if you're at the last notecard. also with the list method you can actually update the list of cards to be read WHILE reading them by adding their names to the front of the list (eg, a special value that is checked for in a notecard, that tells it there's another card to read.)
_____________________
| | . "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... | - 
|
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
07-24-2009 11:05
From: Void Singer you got it =) you can also instead of using a single value, use a list which stores (in reverse order) your notecard names to read, and then on EOF search for the current name, if the current file name index as found in the list is positive, store the next name to read as --index, if the index was 0, trigger whatever you need to signal finished reading notecards. something like... if (EOF == data){ integer vIdxNCName = llListFindList( gLstNCNames, (list)gStrNC ); if (vIdxNCName) { gStrNC = llList2String( gLstNCNames, --vIdxNCName ); }else{ //-- done } }
it could be done in forward order, but it simplifies the math/tests to do reverse order because you don't need to check the length of the list to know if you're at the last notecard. also with the list method you can actually update the list of cards to be read WHILE reading them by adding their names to the front of the list (eg, a special value that is checked for in a notecard, that tells it there's another card to read.) I didn't feel it necessary to start another as my question is right in line with this post. I'm doing a multiple notcard reader that I want to be able to read any combination of up to 12 notecards and store the line info for each card in list and have that list associated with the notecard name. I'm doing a dialog menu that I want to populate the dialog buttons with the name of the notecards and have it pull out that list associated with that notecard. So far I have a good multiple notecard reader going that will store all the line info from all the notecards into one list. I'm trying to figure out how to get the info from each card into it's own list. I've set up 12 diff unpopulated lists in my global varibles. When I call for the notecard line info under DataServer, I have the notecard name indexed but i don't see how to tie that in. A little guidance would be much appreciated. Thanx! 
|
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
07-24-2009 12:35
From: Zena Juran I didn't feel it necessary to start another as my question is right in line with this post. I'm doing a multiple notcard reader that I want to be able to read any combination of up to 12 notecards and store the line info for each card in list and have that list associated with the notecard name. I'm doing a dialog menu that I want to populate the dialog buttons with the name of the notecards and have it pull out that list associated with that notecard. So far I have a good multiple notecard reader going that will store all the line info from all the notecards into one list. I'm trying to figure out how to get the info from each card into it's own list. I've set up 12 diff unpopulated lists in my global varibles. When I call for the notecard line info under DataServer, I have the notecard name indexed but i don't see how to tie that in. A little guidance would be much appreciated. Thanx!  I think I figured it out. I added in 12 if statements, one for each notecard possible notecard that can be indexed, with a function to save the notecard info to a separate list in each statement (my 12 empty global lists. I just really needed to include a counter while I was getting notecard names. 
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-25-2009 09:41
From: Zena Juran I think I figured it out. I added in 12 if statements, one for each notecard possible notecard that can be indexed, with a function to save the notecard info to a separate list in each statement (my 12 empty global lists. I just really needed to include a counter while I was getting notecard names.  Couple of observations here. First, yeah, there's a noticeable speed advantage to reading multiple notecard lines at the same time. Delay in dataserver can be appreciable, so the more llGetNotecardLine()s in-flight at the same time, the better loading performance. Easiest is to read multiple notecards at the same time, but if one has a lot of notecards to process it's also possible to manage a queue of these request IDs so you can have multiple simultaneous requests yet read the separate notecards sequentially. (The ugly bit here is that EOF will be raised after requests have been made for subsequent line numbers.) The advantage to reading them sequentially is that one can then store all the lines in one long ordered list, and use another list to keep indices of where in the big list one notecard ended and the next began. That list of indices would allow a table lookup to replace the twelve if() statements.
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
07-25-2009 10:20
From: Qie Niangao (The ugly bit here is that EOF will be raised after requests have been made for subsequent line numbers.) Not if you got the number of lines first, surely?
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-25-2009 15:23
From: Argent Stonecutter Not if you got the number of lines first, surely? Good point. I pretty much never do that because it's another dataserver event on which to wait, but probably that would be preferable to whacking it up to queuelength-1 times past EOF.
|