Could anyone give us a bit of a Dummies Guide intro to the use of JSON objects in MapTool? Something similar to the excellent walkthru that we got for StrProps and Lists in the b42 revision would be great.
I kinda get the idea of it being a flexible recursive data structure, but exactly how to translate that into practical usage, I just don't quite get it yet. And since it looks like JSON is the way forward with MapTool....
Dr V
req: JSON for Maptool tutorial
Moderators: dorpond, trevor, Azhrei
Re: req: JSON for Maptool tutorial
Agreed. I know it exists, but I have absolutely no idea how to use it.
Mind you, taking several of k.fan's examle macros (like the skill check one) and rewriting them to use JSON would probably also help in understanding how to actually use it.
Mind you, taking several of k.fan's examle macros (like the skill check one) and rewriting them to use JSON would probably also help in understanding how to actually use it.
Re: req: JSON for Maptool tutorial
As for "when/why" to use them, if you're using StrProps and StrLists, JSONs work similarly. The "how" is what's different.
There is a big thread here discussing the main differences.
The only thing that really bugs me with JSONs (and if someone could show me the way to do it differently, thanks) is that there is no "varsFromJSON()" function, and you have to "manually" assign vars, such as:
Which means that big JSONs require LONG lists of variable assignment...
There is a big thread here discussing the main differences.
The only thing that really bugs me with JSONs (and if someone could show me the way to do it differently, thanks) is that there is no "varsFromJSON()" function, and you have to "manually" assign vars, such as:
Code: Select all
[Weapon = json.set("{}", "Name": "Dagger", "Damage": 4, "Speed": 1)]
[Name = json.get(Weapon, "Name")]
[Damage = json.get(Weapon, "Damage")]
[Speed = json.get(Weapon, "Speed")]
Re: req: JSON for Maptool tutorial
There are already 2 tutorials on the wiki for JSONs:
What they are: http://lmwcs.com/rptools/wiki/Introduct ... _Datatypes
Using them in macros: http://lmwcs.com/rptools/wiki/Using_JSO ... _in_Macros
What they are: http://lmwcs.com/rptools/wiki/Introduct ... _Datatypes
Using them in macros: http://lmwcs.com/rptools/wiki/Using_JSO ... _in_Macros
Re: req: JSON for Maptool tutorial
Here's something I just thought of. Call it a varsFromJSON hack:bobthedog wrote:As for "when/why" to use them, if you're using StrProps and StrLists, JSONs work similarly. The "how" is what's different.
There is a big thread here discussing the main differences.
The only thing that really bugs me with JSONs (and if someone could show me the way to do it differently, thanks) is that there is no "varsFromJSON()" function, and you have to "manually" assign vars, such as:
Which means that big JSONs require LONG lists of variable assignment...Code: Select all
[Weapon = json.set("{}", "Name": "Dagger", "Damage": 4, "Speed": 1)] [Name = json.get(Weapon, "Name")] [Damage = json.get(Weapon, "Damage")] [Speed = json.get(Weapon, "Speed")]
Code: Select all
<!-- Create Test JSON -->
[h:testObj = '{"alpha":"1d10", "bravo":6, "charlie":"foo", "delta":"boogers", "echo":99}']
<!-- Generate list of fields in the JSON object -->
[h:varList=json.fields(testObj)]
<!-- loop through that list -->
[h,foreach(var,varList),CODE:
{
<!--get the value at each key in the list-->
[value = json.get(testObj,var)]
<!-- use set to dynamically create variables with the same names as the keys-->
[set(var,value)]
}]
Output:<br>
Variable 1: [alpha]<br>
Variable 2: [bravo]<br>
Variable 3: [charlie]<br>
Variable 4: [delta]<br>
Variable 4: [echo]<br>
Re: req: JSON for Maptool tutorial
Nicely done. And now I'm kicking myself cause I never noticed the "set" function before...Rumble wrote:Here's something I just thought of. Call it a varsFromJSON hack:
Code: Select all
<!-- Create Test JSON --> [h:testObj = '{"alpha":"1d10", "bravo":6, "charlie":"foo", "delta":"boogers", "echo":99}'] <!-- Generate list of fields in the JSON object --> [h:varList=json.fields(testObj)] <!-- loop through that list --> [h,foreach(var,varList),CODE: { <!--get the value at each key in the list--> [value = json.get(testObj,var)] <!-- use set to dynamically create variables with the same names as the keys--> [set(var,value)] }] Output:<br> Variable 1: [alpha]<br> Variable 2: [bravo]<br> Variable 3: [charlie]<br> Variable 4: [delta]<br> Variable 4: [echo]<br>