I'm very new to JavaScript, and programming in general. This question is in the context of an RPG. I have a character object in a combat function, trying to call an ability function based on a) predefined character class, and b) input:
// player example
var player = {
this.pClass = 0; // denotes character class; could also be 1 or 2
}
// ability list
var ability = {
// first character class
0: {
1: function() {some action;},
2: function() {some other action;}
},
// second character class
1: {
// same deal here
}
};
var input = prompt("Enter an action number:");
I would like to be able to call the action by passing the player class and selected number, something like:
ability.{player.pClass}.{input}();
Am I approaching this in the right way, at all? I'd prefer not to iterate if...else if statements for every option, if possible. Thanks for the assistance.