Hi guys. I'm tinkering with various ways of using arrays and/or dictionaries to store various types of data such as character stats and inventory information. I'd like some insight on a specific use case just to be sure that I'm doing things efficiently.
In tabletop RPG games, characters will typically have Ability Scores or Attributes which determine stats such as Strength, Intelligence, Dexterity, and so forth. There is often also an Ability Modifier, which is a bonus or penalty that applies to attack rolls or skill checks as a reflection of the character's general capability. I have a Dictionary object that holds all of the Player's ability scores, which are generated and assigned at the start of the layout. After assigning the ability scores, I'd like to determine the modifiers based on each of those scores.
I have an array which is several elements wide, and two elements tall. The X index contains the possible ability scores that could be generated, and the Y index contains the Modifier for each score — so if the player has Strength 5, and we find the number 5 at index (4, 0), then the correct modifier is located at index (4, 1) and should be assigned as the player's Strength Modifier.
My thought is to loop through the X index looking for player's ability score, and once located, to grab the corresponding modifier from the Y element. Could someone enlighten me as to whether this is the best way to achieve this, and if so, what the code snippet for the loop and for copying the modifier from the array to the dictionary with the player's stats should look like?