(Disclaimer: This is my first time posting here, so please correct me if I made a mistake!) I'm making a character generator for a tabletop RPG, and I want to have the user select a character race (Centaur, Elf, Human, etc.) from a dropdown list. After selection, how can I have it so that the selected race changes other variables for the player character, such as starting stats (increased strength or dexterity, for example) or special skills?
My current code for HTML5 side:
<form>
<label>Enter Character Name:</label>
<!-- Input character name in text field. Name is recorded to JSON variable. -->
<input type="text" id="pcName" name="pcName" required onchange="setName(name)"/>
<label>Select Race: </label>
<!-- Select Race from dropdown menu. On selection, stats/skills/magic are changed.
Also adds racial skills/abilities to proper fields. -->
<select id = "raceList" name="raceList" required onchange="setRace(name)">
<option name="Centaur" id="Centaur">Centaur</option>
<option name="Elf" id="Elf">Elf</option>
<option name="Fae" id="Fae">Fae</option>
<option name="Human" id="Human">Human</option>
</select>
</form>
<label>Enter Attribute Points: </label>
<!-- Enter stats for the character. Based on these numbers entered, attribute tables are altered.
Check to ensure that the numbers entered are not invalid. Recorded to JSON variable. If there were points added from selecting a race, add them here.-->
<input type="text" id="Strength" name="Strength"/>
<input type="text" id="Dexterity" name="Dexterity"/>
<input type="text" id="Intellect" name="Intellect"/>
<input type="text" id="Knowledge" name="Knowledge"/>
<input type="text" id="Endurance" name="Endurance"/>
And my JSON code, with data for the races and an area for the PC's data to be recorded to. When a race is selected, a function (pseudocode after this) parses the JSON data and changes things as needed. For example, the "statModifiers" section adds additional stat points (for example, choosing a Centaur gets you +10 Strength).
{"raceList": [
{"raceName": "Centaur",
"raceAbilities": ["Large Size", "Speed"],
"raceCombatSkills": ["Deadly Charge", "Trample"],
"statModifiers": [10, 0, 0, 0, 0],
"skillModifiers": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"magicModifiers": [0,0,0,0]},
{"raceName": "Elf",
"raceAbilities": [],
"raceCombatSkills": ["Archery"],
"statModifiers": [0, 5, 10, 0, 0],
"skillModifiers": [0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"magicModifiers": [5,0,0,0]},
{"raceName": "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]},
{"raceName": "Human",
"raceAbilities": [],
"raceCombatSkills": [],
"statModifiers": [5, 5, 5, 0, 5],
"skillModifiers": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"magicModifiers": [0,0,0,0]},
"pc": [
{"pcName": "name",
"pcRace": "race",
"pcBuild": "build",
"pcStats": [5,5,5,5,5],
"pcSkills"[20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"pcArmor": [],
"pcItems": []}
]
}
And the JavaScript itself (or rather, what the code is supposed to do, as I'm unsure what code to use):
//Function that, on call, goes through the JSON array for a race object. Then, updates pcRace and pc object with appropriate data.
function setRace(race) {
for (int i = 0; i < raceName.length; i++) {
if (raceList.i.raceName === race) {
pc.pcRace = race;
//Parse JSON data from selected race here, modify "Attribute Points" and related numbers as well
return;
}
}
}