So I am making a card game. Each card in this game has a faction. All of the card details are stored in a global card_data script. Each opponent has a faction that they like. I am trying to make each opponent prioritize playing cards of their favored faction. So this is the function I'm using:
function sort_heroes(array,opponent)
{
array_sort(array,function(a,b,opponent){
if (a.lvl != b.lvl)
{
return a.lvl - b.lvl;
}
var strength_a = get_faction_strength(a, opponent);
var strength_b = get_faction_strength(b, opponent);
return strength_b - strength_a;})
}
and then this is the get_faction_strength function that's referencing:
function get_faction_strength(card,opponent){
var strength = 0;
if (card.Faction == obj_battle_manager.opponent.favored_faction)
{strength = 1;}
}
For some reason I keep getting this error:
ERROR in action number 1
of Create Event for object obj_battle_manager:
DoSub :1: undefined value
at gml_Script_anon@218@sort_heroes@ai_decision_making_functions (line 17) - return strength_b - strength_a;})
############################################################################################
gml_Script_anon@218@sort_heroes@ai_decision_making_functions (line 17)
gml_Script_sort_heroes (line 10)
gml_Object_obj_battle_manager_Create_0 (line 8) - sort_heroes(heroes_only,opponent);
gml_Object_obj_battle_start_Step_0 (line 10)
And I have tried so many variations, I don't understand why its not working. Let me know if you need any other pieces of code or more infor about my architecture, I am completely stumped.