Skip to content

Current questions and answers regarding the map editor.

User Avatar
#5976
Auto-translated
Gerter
You can have hundreds of threads running simultaneously, and the game will handle it fine. However, you shouldn't continuously check certain things in an infinite loop, such as calculating the path cost in movement using a specific function – this can crash the game even with a single thread.
Well, the fact that there's no low limit on the number of threads that can be opened is a good thing!

As for things that shouldn't be checked in an infinite loop: I use the following checks in my script; I assume these are acceptable?

1) Checking if an event occurs after a certain number of days (e.g., unlocking a region, updating a quest), eventDay is a global variable
function waitForEvent()
   while (1) do
      sleep(10)
      local currentDay = GetDate(DAY)
      if ((currentDay - eventDay) == 5) then
         --some code
         break
      end
      sleep(10)
   end
end

2) Checking if the player has no towns and active heroes
function checkGoalCompletion()
   while (1) do
      sleep(10)
      local heroes = GetPlayerHeroes(id)
      local townsNumber = 0;
      for i, town in TOWNS do
         if (GetObjectOwner(town) == id) then
            townsNumber = townsNumber + 1
         end
      end
      if (heroes == 0 and townsNumber == 0) then
         --some code
         break
      end
      sleep(10)
   end
end

3) Checking if the required number of creatures is present in the town's garrison
function checkTownCreatures()
   while (1) do
      sleep(10)
      local creatures = GetObjectCreatures(obj, id)
      if (creatures >= NEEDED) then
         --some code
         break
      end
      sleep(10)
   end
end

Сценарии:
"Холм мертвецов"
"Священное древо"