Using JSON to change a displayed number or string? Using JSON to change a displayed number or string? json json

Using JSON to change a displayed number or string?


Personally, I'd reorganize your raceList to be an object literal keyed off of the race name:

raceList = {"Fae" : {     "raceAbilities": ["Silent Casting", "Cast While Moving"],     "raceCombatSkills": [],    "statModifiers": [5, 0, 0, 0, 5],     "skillModifiers": [0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],     "magicModifiers": [15,0,0,15] },     { "Human" : { //... }}

Now to find the relevant entry, I can just key off the name instead of iterating through an array:

function setRace(race){    var raceStats = raceList[race];}

But if you can't do that, then searching the array works too.

Now for updating your pc, just iterate through the modifiers from raceStats and add them to your pc, for example:

for(var i=0; i < pc.pcStats.length; i++) {    pcStats[i] += raceStats.statModifiers[i];}

And so on...