About

Updates the key-value pair string kvp with the parameters from a string data and returns the result as a key-value pair.

Prototype

  • Requires data string in description format, eg variable_1=value_1&variable_2=value_2.
  • Updates the key-value pair kvp, setting the new variables from data and leaving the rest of the variables intact.
  • Returns a key-value pair string.

Error Handling

  • The function will ensure to return a properly formatted key-value pair with every key being unique.

Examples

Updating Variables

Suppose that the object description is:

toggle=on&target=<0,0,1>&sound=off

and that we call the function as:

llSetObjectDesc(wasKeyValueUpdate("toggle=off&sound=on", llGetObjectDesc()));

then the object description will be updated to:

toggle=off&target=<0,0,1>&sound=on

Partial Updates

Suppose that the object description is:

toggle=on&target=<0,0,1>&sound=off

and that we call the function as:

llSetObjectDesc(wasKeyValueUpdate("toggle=off&special=k", llGetObjectDesc()));

then the object description will be updated to:

toggle=off&target=<0,0,1>&sound=off

The extra key-value pair special=k gets ignored.

Code

This script was tested and works on OpenSim version 0.7.4!

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueUpdate(string in, string up) {
    list org = llParseString2List(in, ["&", "="], []);
    list dst = llParseString2List(up, ["&", "="], []);
    list out = [];
    do {
        if(llListFindList(org, [llList2String(dst, 0)]) == -1) {
            out += llList2String(org, 0) + "=" + llList2String(org, 1);
            jump continue;
        }
        out += llList2String(org, 0) + "=" + llList2String(dst, 1);
@continue;
        dst = llDeleteSubList(dst, 0, 1);
    } while(llGetListLength(dst) != 0);
    return llDumpList2String(out, "&");
}

fuss/data_structures/key-value_pairs/update.txt ยท Last modified: 2019/01/03 01:38 (external edit)

Access website using Tor Access website using i2p


For the copyright, license, warranty and privacy terms for the usage of this website please see the license, privacy and plagiarism pages.