A while back I started to wonder if I was missing some helpful functionality with Json, so I started working with various bits of test scripts to try and get a grip on how things work. I found the json tutorials and wiki pages on the RPTools Wiki. Despite that, I kept running into wall after wall after wall where things did not work as I expected.
One of the challenge I have been hitting the wall with is that I do not know what functionality json can provide. Also, how should I form the data structure so I can take advantage of the functionality that does exist. From looking at Json in general, I can't help but think that it can be object oriented so I can add and subtract whole datasets, but I have not been able to make it work.
It is difficult to figure out what questions to ask because I just cannot get a grip on how things should work. I am hoping someone can give me some direction, tutorials, or work with me on some sample code.
To start, I would like to come up with a data structure I know is valid.
Secondly, I am hoping to confirm that my assumptions are correct or not on how Json can be used.
I am not worried about the specific use of Json functions at this point as I can delve into the how-to later on.
Here is a sample I worked up for a variable called "SaveArray" if someone is willing to work with me on it. I know the formatting is not consistent, but I hope it makes it more readable...
Code: Select all
{ "SavingThrow":"Fortitude": {
"Class":"Paladin": {
"ClassBase" : {"Desc":"Base", "Type":"None", "Value":4 },
"ClassMod": { "Desc":"Divine Grace", "Type":"None", "Value":2 }
},
"RaceMod" : {"Desc":"Dwarf", "Type":"Racial", "Value":2 },
"AbilityMod" : {"Desc":"Constitution", "Type":"ConMod", "Value":3 }
"ItemMod": { "Desc":"Ring of Protection +1", "Type":"Deflection", "Value":1 },
"ItemMod": { "Desc":"Luck Blade +2", "Type":"Luck", "Value":1 },
"MagicMod": { "Desc":"Guidence", "Type":"Competence", "Value":1 }
},
"SavingThrow":"Reflex": {
"Class":"Paladin": {
"ClassBase" : {"Desc":"Base", "Type":"None", "Value":1 },
"ClassMod": { "Desc":"Divine Grace", "Type":"None", "Value":2 }
},
"RaceMod" : {"Desc":"Dwarf", "Type":"Racial", "Value":0 },
"AbilityMod" : {"Desc":"Dexterity", "Type":"DexMod", "Value":-1 }
},
"SavingThrow":"Will": {
"Class":"Paladin": {
"ClassBase" : {"Desc":"Base", "Type":"None", "Value":1 },
"ClassMod": { "Desc":"Divine Grace", "Type":"None", "Value":2 }
},
"RaceMod" : {"Desc":"Dwarf", "Type":"Racial", "Value":0 },
"AbilityMod" : {"Desc":"Wisdom", "Type":"WisMod", "Value":0 }
}
2) I am also assuming that I am able to have multiple objects with the same name within the same structure such as "ItemMod", as long as I recursively check for more than one instance of these objects.
3) The structure I chose above was intended to allow me to have a single variable called SavingThrow Array that contains all of the data that affects a saving throw. Then, if an item is equipped or a spell is cast on a character, I can add a new internal object to the appropriate Saving Throw so it is ready when the player needs to make a roll. Is this a good way to set it up or is there a better way?
A few other questions:
1) Is it better or worse to have the values of the objects in quotes, eg "Value":"1".
2) When enclosing strings, is there any benefit (visually or functionally) whatsoever to using quotes vs apostrophes?
This whole conundrum on whether to use Json or not has essentially stopped me from continuing work on my campaign framework completely.
I am pretty sure me asking for help on this is a pretty big 'ask', so any assistance at all is really appreciated.