SC2Mapster Forums

Development > Triggers

There has to be a better way to script this.

    #23 Dec 06, 2012 at 22:56 UTC - 0 likes

    the action I call at the very end of the mapInit does now loo like this:
    http://i.imgur.com/WuTvd.png
    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.

    A programmer started to cuss
    Because getting to sleep was a fuss
    As he lay in his bed
    Looping 'round in his head
    Was: while (!asleep()) sheep++;

    twitter.com/SC2IncomeWars
    facebook.com/SC2IncomeWars

    #24 Dec 06, 2012 at 23:30 UTC - 0 likes

    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!

    Last edited Dec 06, 2012 by Monkalizer
    #25 Dec 07, 2012 at 17:30 UTC - 0 likes

    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.

    #26 Dec 07, 2012 at 20:27 UTC - 0 likes

    @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.

    #27 Dec 08, 2012 at 12:47 UTC - 0 likes

    @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)

    Last edited Dec 08, 2012 by b0ne123

You must login to post a comment. Don't have an account? Register to get one!