Skip to content
User Avatar
#4035
Auto-translated
Dogenator, it's clearly necessary to check the correctness of the GetTownRace function: 1. Are the town names definitely 'player_1' and 'player_2'? 2. Does the race you need actually have the ID 1? And what exactly does this function return? According to the documentation, it returns RaceID, where 1 is RACE_RANDOM_TYPE, but I haven't used it myself, so I'm not entirely sure. In general, using numbers instead of clear identifiers is a path to debugging hell. You can write print(GetTownRace('player_1')) in the console and see what it actually returns. The sleep() function is used unnecessarily in this script. The two main cases for its use are: 1. Almost all functions that work with map objects (monsters, buildings, heroes, etc.) are executed, let's say, not instantaneously. For example, you want to attach a touch handler to an enemy hero. To do this, you must disable the standard handler and only then attach your own; these are the rules of the game. But if you write: ```lua SetObjectEnabled(hero, nil); -- disabling the standard hero touch trigger Trigger(HERO_TOUCH_TRIGGER, hero, func); -- setting your own touch trigger ``` It won't work because SetObjectEnabled(hero, nil); is not executed instantaneously and won't complete before the trigger (this is a simplified explanation; the reasons are slightly different). In such cases, you should always use sleep(): ```lua SetObjectEnabled(hero, nil); -- disabling the standard hero touch trigger sleep(1); -- minimal delay, usually 1 is enough Trigger(HERO_TOUCH_TRIGGER, hero, func); -- setting your own touch trigger ``` 2. And, of course, when various animations, effects, and pop-up messages are created on the map, sleep() is used to set delays for them.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо