LSL: Read Notecard

string CONFIG_NOTECARD = "notecard";
key card_query;
integer line;
 
state default {
    state_entry() {
        if (llGetInventoryType(CONFIG_NOTECARD) == INVENTORY_NOTECARD) {
            // Read the notecard
            card_query = llGetNotecardLine(CONFIG_NOTECARD, line=0);
        }
    }
 
    dataserver(key queryid, string data) {
        if (queryid == card_query) {
            if (data != EOF) {
                // Skip comments
                integer ix = llSubStringIndex(data,"#");
                if (ix != -1) {
                    if (ix == 0) {
                        data = "";
                    } else {
                        data = llGetSubString(data, 0, ix-1);
                    }
                }
 
                // If the data looks like a key...
                if ((data != "") && (data != "#") && (((key)data) != NULL_KEY) ) {
                    // Process line
                    // ...
                }
                // Read next line
                card_query = llGetNotecardLine(CONFIG_NOTECARD, ++line);
            } else {
                // Done
                log("Configuration complete");
            }
        }
    }
}