the action I call at the very end of the mapInit does now loo like this:
to get your map regionId, create some trash code and let the editor show you your current code position or use another array containing all your relevant regions and replace the getRegionfromid with the array.
You could use two loops and get efficient and everything done in a few lines.
The unit enters/leaves region is bad in another way: if you create a unit inside the region it wont fire. It only fires if the unit "walks over the borders". My solution, which i personally think is much better is to continously count the number of units of a specific type inside a region. If you do this in a threaded function with a while-loop in it with a wait of 0.1 seconds, nobody will detect any difference. You can even set it lower if its not a "high-action" region (for score and such).
Best thing is that it does not matter much if its one unit or 200 thats inside the region ^^
Summary: stay away from unit enters region and go while-loop!
Hm. You are probably right about how it checks all the units on the map. The fact that you can control how many checks you do is still a good thing. You have no control of how many time it checks, and you will get performance chokepoints if many units enters many regions simultaneously (or so i believe...). A third way which i use sometimes (if its a single unit) is to use distance between points, with the hero being a object point and the targets being pushed into an array, and then checking those.
If you have an "any unit enters"-event, it will have more performance problems than your workaround.
But if you use variables as shown above to specify the few checked units, it should improve the performance. It should now check only the 6 units which are important and not the other 200 which are unable to even reach the areas due to terrain restrictions.
distance between points doesn't work for rectangular regions and a simple comparison xy of unit > region x1y1 and xy < x2y2 should be faster than sqrt((ux-px)^2 + (uy-py)^2)
the action I call at the very end of the mapInit does now loo like this:
to get your map regionId, create some trash code and let the editor show you your current code position or use another array containing all your relevant regions and replace the getRegionfromid with the array.
You could use two loops and get efficient and everything done in a few lines.
The unit enters/leaves region is bad in another way: if you create a unit inside the region it wont fire. It only fires if the unit "walks over the borders". My solution, which i personally think is much better is to continously count the number of units of a specific type inside a region. If you do this in a threaded function with a while-loop in it with a wait of 0.1 seconds, nobody will detect any difference. You can even set it lower if its not a "high-action" region (for score and such).
Best thing is that it does not matter much if its one unit or 200 thats inside the region ^^
Summary: stay away from unit enters region and go while-loop!
This is not a good way either isn't it?
I think it would still check all units on the map to figure out if they are in the region.
But even if it would be good. It doesn't because I have 1 unit per players and 100 different regions this unit may enter.
@b0ne123: Go
Hm. You are probably right about how it checks all the units on the map. The fact that you can control how many checks you do is still a good thing. You have no control of how many time it checks, and you will get performance chokepoints if many units enters many regions simultaneously (or so i believe...). A third way which i use sometimes (if its a single unit) is to use distance between points, with the hero being a object point and the targets being pushed into an array, and then checking those.
@Monkalizer: Go
If you have an "any unit enters"-event, it will have more performance problems than your workaround.
But if you use variables as shown above to specify the few checked units, it should improve the performance. It should now check only the 6 units which are important and not the other 200 which are unable to even reach the areas due to terrain restrictions.
distance between points doesn't work for rectangular regions and a simple comparison xy of unit > region x1y1 and xy < x2y2 should be faster than sqrt((ux-px)^2 + (uy-py)^2)