@ady624: while i was in there doing the *CLEAR
https://community.webcore.co/t/clearing-a-list/1345/11?u=bangali
thought i might as well add a stuff method for lists. so, added a stuff method for use like this
set variable lightNames[*ALL] = “0:light 1,1:light 2,2:light 3”
which gives:
lightNames = {“0”:“light 1”, “1”:“light 2”, “2”:“light 3”}
seems to be working as desired. not sure if there might an unwanted side effect from replacing the entire variable value instead of just a single indexed value in the list?
thanks!
/******************************************************************************/
/*** stuff returns a map used to initialize a list variable. called from ***/
/*** setvariable when set variable list[*ALL] = "idx:value,idx:value" ***/
/******************************************************************************/
private stuff(rtData, variable, value) {
if (!value)
return [t: "error", v: "Invalid value. Expecting value in form 'idx:value,idx:value'"];
def list = value.split(',').toList()
if (list.size() <= 0)
return [t: "error", v: "Invalid value. To clear the list use set variable list[*CLEAR] = ''"];
def mappedValue = [:]
list.each {
def splitIt = it.indexOf(':')
def listIDX = it.substring(0, splitIt)
def listValue = it.substring(splitIt+1, it.size())
if (listIDX.size() < 1)
mappedValue << [t: "error", v: "Invalid value. Each list item must be in form 'idx:value'"];
else
mappedValue.put(listIDX, cast(rtData, listValue, variable.t.replace('[]', '')));
}
return mappedValue
}
EDIT: updated to use cast(…)