Table of Contents

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

Error Handling

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, "&");
}