json.append() and empty properties
Posted: Wed Jun 30, 2010 11:18 am
One last query (for now):
I want to store some JSON Objects in a JSON Array and store the array in a property. I want to be able to add and remove object from the JSON Array whenever I like. I am trying to add items using this macro:
The problem that I keep running into is that it is impossible for me to tell whether or not there is already a JSON Array assigned to the property. Wiki: json.type() won't tell me if weaponProperty contains a JSON Array or not (returns UNKNOWN regardless of what the value of my property is), and if there is a JSON Array already there then the Wiki: if() statement throws an invalid condition error.
Is there a better mousetrap for this quandary?
I want to store some JSON Objects in a JSON Array and store the array in a property. I want to be able to add and remove object from the JSON Array whenever I like. I am trying to add items using this macro:
Code: Select all
[h:meleeWeaponList = meleeWeaponList()]
[h:weaponList = ""]
[h,foreach(element, meleeWeaponList):
weaponList = listAppend(weaponList, element)]
[h:okay = input(
"selection|" + weaponList + "|Choose a weapon to add|LIST|SELECT=0 VALUE=STRING"
)]
[h,if(okay == 1), code:{
[h:weaponStats = json.get(meleeWeaponList, selection)]
[h:weaponProperty = getProperty("Weapons", getSelected())]
[h:weaponProperty = if(weaponProperty == "", "[]", weaponProperty)]
[h:weaponProperty = json.append(weaponProperty, weaponStats)]
[h:setProperty("Weapons", weaponProperty, getSelected())]
[macro("DisplayCharacterSheet@Lib:WFRP"):""]
}]
Is there a better mousetrap for this quandary?