Skip to content

Current questions and answers regarding the map editor.

User Avatar
#4492
Auto-translated
It seems like the `CreateMonster` function is being called incorrectly, and Lua doesn't understand it:
mood= MONSTER_MOOD_AGGRESSIVE,courage= MONSTER_COURAGE_CAN_FLEE_JOIN,rotation= 0
The parser probably crashed on this line. Second, if the script crashes, it's good practice to check the console and provide the error message here (it can often help you understand the problem yourself). Third, if you're aiming for a moderately complex scripted map (>200 lines of code), I recommend a different approach to code structure. Currently, all your initialization functions are located at the top level in a disorganized manner. As a result, even a small error in the code can cause the interpreter to crash, the scripts to stop working completely, and, most importantly, it becomes unclear where to look for the problem. I recommend placing everything that is executed directly when the map starts into a separate function, supplementing it with periodic `print` statements:
function InitMap()
print('init start');

EnableHeroAI('Brem', nil);
EnableHeroAI('Straker', nil);
print('init heroes OK');

Trigger(REGION_ENTER_AND_STOP_TRIGGER, "rew", "rewF" );
Trigger(PLAYER_REMOVE_HERO_TRIGGER, PLAYER_2, 'Player2LoseHero');
print('init triggers OK');

print('init finish');
end

InitMap();
This code is placed at the very end of the script, and when the map starts, we first look at the console. If there is a syntax error in the code that the Lua interpreter cannot handle, the console will be empty; the `InitMap()` function will simply not be reached. If everything is fine, the console will end with the line 'init finish'. If we try to initialize something incorrectly, for example, we make a mistake with the region name "rew", the console will show:
init start
init heroes OK
some error in red font
and based on this log, it will be immediately clear in which lines to look for the error.