Connection ErrorBad RequestThis page went staleSession ExpiredSign in requiredForbiddenNot FoundToo Many RequestsServer ErrorBad GatewayService UnavailableGateway TimeoutHTTP Version Not Supported
Session Expired
Your session has expired. Please log in to continue.
Sign in required
You need an account to do that. Sign in or create one — it only takes a minute.
This page went stale
Your security token was rejected, usually because the page sat open too long or you signed in elsewhere. Nothing was saved. Reload the page and try again.
Request Failed
We encountered an issue while processing your request.
Please check your internet connection and try again.
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: ЧаВо