Skip to content
User Avatar
#3889
Auto-translated

Hello everyone!

Using the Manuals, I decided to try creating a combat script.
I encountered a couple of problems with it:
1) The function GetDefenderCreatures() gives an error: "Wrong type of argument 1 when calling function GetUnits", regardless of where I call it in the script file. I tried a similar function for the attacker - GetAttackerCreatures(). It worked the first time, but the second time, the same problem occurred as with Defender.
2) The DefenderHeroMove(heroName) and AttackerHeroMove(heroName) hooks do not trigger during hero turns - there is not even a message in the console that the script entered the function body, and no error is displayed either. Once, the AttackerHeroMove(heroName) hook even got stuck in a loop. Only the Prepare() and Start() hooks work consistently.
Could you please advise on how to resolve these issues?

Script content (for now, just logs to understand what works and what doesn't):

print("inside combat file");

DEFENDER = GetDefenderHero();
print(DEFENDER);
ATTACKER = GetAttackerHero();
print(ATTACKER);
defenderCreatures = {0};
attackerCreatures = {0};


function Prepare()
  print("inside Prepare function");
  print("Prepare function has ended");
end;

function Start()
  print("inside Start function");
  ShowFlyingSign(GetMapDataPath().."CombatMessage.txt", DEFENDER, 200);
  defenderCreatures = GetDefenderCreatures();
  attackerCreatures = GetAttackerCreatures();
  print(1);
  for key, creature in defenderCreatures do
    print("key=", key, ", creature=", creature);
  end;
  print(attackerCreatures);
  print("Start function has ended");
end;

function DefenderHeroMove(heroName)
  print("inside DefenderHeroMove function");
  ShowFlyingSign(GetMapDataPath().."CombatMessage.txt", DEFENDER, 200);
  print("DefenderHeroMove function has ended");
end;

function AttackerHeroMove(heroName)
  print("inside AttackerHeroMove function");
  ShowFlyingSign(GetMapDataPath().."CombatMessage.txt", DEFENDER, 200);
  print("AttackerHeroMove function has ended");
end;