An extended version using states to do this cleanly
list gData = [];integer gDataCount;integer gDataLine;list gNoteNames;integer gNoteCount;integer gNoteIndex;/* initialize -------------------------------------------------------------*/default{ state_entry() { llSetText("Initializing... please wait", <1.0,0.0,0.0>, 1.0); gNoteCount = llGetInventoryNumber(INVENTORY_NOTECARD); llWhisper(0, (string)gNoteCount); integer i; for (i = 0; i < gNoteCount; i++) gNoteNames += [llGetInventoryName(INVENTORY_NOTECARD, i)]; gNoteIndex = 0; state data; }}/* data fetch -------------------------------------------------------------*/state data{ state_entry() { llSetText("Fetching data... please wait", <0.0,0.0,1.0>, 1.0); gData = []; gDataLine = 0; llGetNotecardLine(llList2String(gNoteNames, gNoteIndex), gDataLine); } dataserver(key id, string data) { if (data != EOF) { gData += [data]; llGetNotecardLine(llList2String(gNoteNames, gNoteIndex), (++gDataLine)); } else // no more lines of data in notecard state main; } state_exit() { gDataLine = 0; gDataCount = llGetListLength(gData); gNoteIndex = ((++gNoteIndex) % gNoteCount); } }/* ---------------------------------- put user actions in state main*/state main{ state_entry() { llSetText("Ready for user actions", <0.0,1.0,0.0>, 1.0); } touch_end(integer n) { llSay(0, llList2String(gData, gDataLine)); if ((++gDataLine) == gDataCount) state data; }}
When doing this kind of task then the prequisite is that we are going to partition the data in some way Option 1) partition the data into separate files (multiple notecards) and treat each file as a page. A synchronous application operation when using states Option 2) retain the data in one file (single notecard) and do in-memory paging The downside with option 1 is the delay when reading pages from file into memory The downside with option 2 is that this is an asynchronous operation. The main issue is with the reader while the in-memory page is being updated, so that the reader doesn't get invalid data Approaches for Option 2 are: a) pause the application interactions while reading, making the application synchronous b) remain application asynchronous by implementing a reader request queue manager as well as a data request manager