This may be related and a possible cleaner solution, but I have some code like this:
Code: Select all
@@setDefaultConfig
[H: assert(isGM(),"GM Only Function: ["+getMacroName()+"] You do not have permission.",0)]
[H: optionMenu = json.set("{}",
"optionTab",json.set("{}","default","Options","prompt","","type","TAB","options",""),
"editMode",json.set("{}","default","{editMode}","prompt","Turn on Edit Mode","type","CHECK","options",""),
"reSort",json.set("{}","default","{reSort}","prompt","Re-sort buttons by color on Save","type","CHECK","options",""),
"cleanComment",json.set("{}","default","{cleanComment}","prompt","Change line comments to statements","type","CHECK","options",""),
"showTabGroups",json.set("{}","default","{showTabGroups}","prompt","Show TAB Groups for Multi Macro Select","type","CHECK","options",""),
"adminTab",json.set("{}","default","Admin","prompt","","type","TAB","options",""),
"formWidth",json.set("{}","default","{formWidth}","prompt","Set Form Width","type","TEXT","options",""),
"formHeight",json.set("{}","default","{formHeight}","prompt","Set Form Height","type","TEXT","options",""),
"makeConfigDefault",json.set("{}","default",0,"prompt","Make these config settings default","type","CHECK","options",""),
"resetDefaults",json.set("{}","default",0,"prompt","Reset Default Config","type","CHECK","options",""))]
[H: am.mio.slp("mio.optionMenu",optionMenu)]
[H: am.mio.slp("mio.options",json.set("{}","editMode",0,"reSort",0,"cleanComment",0,"showTabGroups",0,"formWidth",92,"formHeight",40))]
[H: macro.return = optionMenu]
Notice the braces "{}" around the variable names {editMode} and the like. This will, when I run
Wiki: json.evaluate() get the current values and put them in to the object. This doesn't work for the json keys, only the values (i think).
Code: Select all
@@configOptions
@PROPS@ fontColor=black;autoExecute=true;fontSize=1.00em;sortBy=;color=default;playerEditable=false;applyToSelected=false;group=;tooltip=
[H: assert(isGM(),"GM Only Function: ["+getMacroName()+"] You do not have permission.",0)]
[H: id = arg(0)]
[H: defaultOptions = am.mio.loadOptionsLocally()]
[H: optionMenu = am.mio.glp("mio.optionMenu")]
[H, if(json.isEmpty(optionMenu)): optionMenu = am.mio.setDefaultConfig()]
[H: menuStr = ""]
[H, foreach(option,optionMenu), code: {
[H: menuObj = json.evaluate(json.get(optionMenu,option))]
[H: varsFromStrProp(json.toStrProp(menuObj))]
[H, if(type == "PROPS"): default = decode(default)]
[H: menuStr = json.append(menuStr,strformat("%s|%s|<html><b>%s</b></html>|%s%s",option,default,prompt,type,if(!json.isEmpty(options),"|"+options,"")))]
}]
[H: hasInput = input(json.toList(menuStr,"##"))]
[H: abort(hasInput)]
[H, if(!isNumber(formWidth)): formWidth = 92]
[H, if(!isNumber(formHeight)): formHeight = 40]
[H, foreach(option,defaultOptions): defaultOptions = json.set(defaultOptions,option,eval(option))]
[H: setProperty("mio.options",defaultOptions,id)]
[H, if(makeConfigDefault): am.mio.slp("mio.options",defaultOptions)]
[H, if(resetDefaults): am.mio.setDefaultConfig()]
The first half of the above code can be used to build any input menu, in fact I think I'll make it a separate function. There is no real benefit to doing it this way unless you want to be able to config the config options, but it seemed like a good programming exercise.
See if this code works:
Code: Select all
[H: jsonResult = json.set("{}","useDistance",0,"x","{c}","y","{r}","layer","{'layer'+tokenName}","facing","{'rotate'+tokenName}",
"size","{listGet('sizeList'+tokenName,roll(1,listCount('sizeList'+tokenName))-1)}")]
[H: evalResult = json.evaluate(jsonResult)]