Moderator
M
Moderator
12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.
00:14, 18th Jul 2012
Magtheridon96:
IcemanBo: Too long as NeedsFix. Rejected.
00:14, 18th Jul 2012
Magtheridon96:
- 3 groups per instance is just overkill :/
1 group or a table of units would suffice.
You could attach an integer to each unit so you can separate them
instead of having 3 groups. - Instead of using the old fashioned way of iterating through units
in a group, we now use "First of group" loops.
JASS:/* * First we need a dummy group to use. * Users have the option to use bj_lastCreatedGroup, * but due to certain bugs involved with nesting * group enumerations, I would highly recommend * that you do not. */ globals private group enumGroup = CreateGroup() endglobals /* * This function takes a unit and returns a boolean. * It's used to filter out unwanted units in our * group enumeration. */ function filter takes unit filterUnit returns boolean return true endfunction /* * This function takes the unit that we are iterating * over currently in our group enumeration and does * stuff to him. Really cool stuff if you ask me. */ function actions takes unit enumUnit returns nothing call DoNothing() endfunction function Enumerate takes nothing returns nothing /* * This is the unit we are going to use * in our group enumeration loop. */ local unit enumUnit /* * These are just here so that the code * would compile. They represent the * coordinates of the point that you want * to reference when selecting units in * range. The range variable represents * ... range. */ local real x = 0 local real y = 0 local real range = 0 /* * This function will clear the group * and select all units in range of * point(x,y). */ call GroupEnumUnitsInRange(enumGroup, x, y, range, null) /* * This is where the actual iteration is done. */ loop /* * First we get a unit from the group. * After that, we confirm that this unit is * not null. Getting a null unit indicates * that a group is empty. Finally, we remove * this unit from the group so that we don't * iterate over him more than once. */ set enumUnit = FirstOfGroup(enumGroup) exitwhen enumUnit == null call GroupRemoveUnit(enumGroup, enumUnit) /* * Now that we have our unit, we attempt * to filter him out. If he passes the filter, * actions will be executed for him. */ if filter(enumUnit) then call actions(enumUnit) endif endloop endfunction
- You don't need to inline
TriggerRegisterAnyUnitEventBJ
- When comparing the distances, you don't need to use the SquareRoot, you can just multiply the constant by itself and compare your expression with that. It's faster because SquareRoot is a pretty slow function.
- Use TimerUtils instead of pausing and destroying the timers only if you want to.
- Don't create a local group, then enumerate and destroy it, use a global group instead.