You could change your project to use JavaScript Generic Objects to store both the traits for each person as well as all the people in your project.
1. Using Generic Objects to define your people.
/* Initialise the Generic Object being used to store the people. */
<<set $npcs to {}>>
/* Define the generic object being used to store Bob's properties (traits).
With quoted property names and code formating.
*/
<<set $npcs.Bob to {
"Luck": 7,
"Strength": 6
}>>
/* Define the generic object being used to store Bill's properties (traits).
Without quoted property names, with code formating.
*/
<<set $npcs.Bill to {
Luck: 5,
Strength: 8
}>>
/* Define the generic object being used to store Jane's properties (traits).
Without quoted property names or code formating.
*/
<<set $npcs.Jane to {Luck: 5, Strength: 8}>>
notes:
a. The text between the /* and */ markings is knows as a comment, you can safely remove both the text and the markings.
b. The open & close curly braces { } represent a generic object literal value, the one being assigned to the $npcs story variable represents an empty object.
c. A Generic Object can be assigned one or more 'properties', a property consists of three parts.
- The Property's Name, this is the value before the colon and this value is generally a String without space characters. Property Names are also knows as Keys.
- The colon, uses seperate the Property Name from the Property Value.
- The Property' Value, which can be any valid JavaScript data-type.
d. JavaScript supports using Property Names without quotes when declaring the properties of a Generic Object.
2. Using different 'notation' to access the properties of an Object.
There are two different notations you can use to reference an object's property.
a. Dot Notation, this is what is being used to define each of the people above and looks like the following.
$npcs.Bob.Luck
b. Bracket Notation, this is when you use a Name String value to reference a property,
$npcs["Bob"]["Luck"]
You can use Bracket Notation to solve your issue of being able to generically access both a person and a trait in your AddTrait Passage.
<<set $person to "Bob", $action to "Luck">>
/* Output the person's name, the trait's name, and the trait's value. */
person: $person trait: $action value <<= $npcs[$person][$action] >>