Code: Select all
[h: assert(getSelected()!='',"You must select token(s) to use this command.",0)]
[h: campaignStatesJSON = json.get(getInfo("campaign"),"states")]
[h: statesTokenJSON = json.get(campaignStatesJSON,"Tokens")]
[h: statesList = json.toList(statesTokenJSON)]
[h: stateSelectInput = strformat("stateID | %{statesList} | Select State Type | LIST | SELECT=0 VALUE=STRING")]
[h: durationInput = strformat("duration| 1 | State duration in rounds")]
[h: conversionSet1 = strformat("junkvar| 10 rounds | Turn | LABEL")]
[h: conversionSet2 = strformat("junkvar| 60 rounds | Hour | LABEL")]
[h: conversionSet3 = strformat("junkvar| 1440 rounds | Day | LABEL")]
[H: status = input(
stateSelectInput,
conversionSet1,
conversionSet2,
conversionSet3,
durationInput
)]
[H: abort(status)]
[h: statesJSON = getLibProperty("tokenStates","Lib:ADND")]
[h: currentSelections = getSelected()]
[foreach(id,currentSelections,""), code :{
[h: addThisJSON = "{}"]
[h: addThisJSON = json.set(addThisJSON,"tokenID",id)]
[h: addThisJSON = json.set(addThisJSON,"stateID",stateID)]
[h: addThisJSON = json.set(addThisJSON,"duration",duration)]
[h:'-->'][h: statesJSON = json.append(statesJSON,addThisJSON)]
[h: setState(stateID,id,1)]
}]
[h: setLibProperty("tokensStates",statesJSON,"Lib:ADND")]
Code: Select all
{"tokenID":"000000002E13816D8560000000000000","stateID":"Acid","duration":1}
Code: Select all
statesJSON = json.set(tokenID,addThisJSON)
Anyone have a suggestion on how to do this?