Right now i am working on a Heroes 3-like combat system, and since i also want to improve my efficient-coding skills, i have a few questions regarding that matter:
1. Constant variables or constant functions? I know they are used in defining configuration values that don't change throughout the game, but which method is better to use? Or do one perform better than the other in some specific tasks?
2. FirstOfGroup loops, unit comparison loops. I've heard they are slow and inefficient, but i can't think of a loop which would accomplish the same goal, but would be more efficient. Should i compare handle id's instead, or put units in a global array and then loop through its' indexes?
3. Struct members vs. GetUnitAbilityLevel(). The reason i'm asking this question is because each unit has a struct instance associated with it, and this struct has approx. 15 members, therefore i'm becoming anxious of adding even more members to it (tho number of these structs will almost never exceed 14). Since some of these members are booleans describing the units' state, i thought about replacing them with abilities and simply checking whether the unit has a certain ability or not. Should i be concerned about those structs and use abilities, or are booleans a better option?
4. Dynamically creating and destroying a trigger. I have a function which looks like that:
Should this kind of action be avoided, or is it reasonable in this case? I'm concerned because i've read that creating and destroying triggers within short periods of time is generally bad. This function runs once per approx. 5-10 seconds, so it's not that rapid, also it has no intersections with other functions.
5. Reversing structs. I have a struct, and a unit that is its' member. Now i know have the unit variable, but i need to retrieve to what struct instance it belongs. Is there another way to accomplish that, other than looping through all struct instances and comparing their members to the variable?
1. Constant variables or constant functions? I know they are used in defining configuration values that don't change throughout the game, but which method is better to use? Or do one perform better than the other in some specific tasks?
2. FirstOfGroup loops, unit comparison loops. I've heard they are slow and inefficient, but i can't think of a loop which would accomplish the same goal, but would be more efficient. Should i compare handle id's instead, or put units in a global array and then loop through its' indexes?
3. Struct members vs. GetUnitAbilityLevel(). The reason i'm asking this question is because each unit has a struct instance associated with it, and this struct has approx. 15 members, therefore i'm becoming anxious of adding even more members to it (tho number of these structs will almost never exceed 14). Since some of these members are booleans describing the units' state, i thought about replacing them with abilities and simply checking whether the unit has a certain ability or not. Should i be concerned about those structs and use abilities, or are booleans a better option?
4. Dynamically creating and destroying a trigger. I have a function which looks like that:
JASS:
function DestinationDo takes nothing returns nothing
set HCS_dr = true
endfunction
function SomeFunc takes nothing returns nothing
// (...)
set HCDestinationTrig = CreateTrigger()
call TriggerRegisterUnitInRange(HCDestinationTrig, GetOrderTargetUnit(), DEST_RANGE(), e)
call TriggerAddAction(HCDestinationTrig, function DestinationDo)
// DestinationDo is meant to run only when a unit comes within range of a very
// specific unit, therefore the trigger must have only one event registered.
loop
exitwhen HCS_dr == true
call TriggerSleepAction(0)
endloop
set HCS_dr = false
call DestroyTrigger(HCDestinationTrig)
call DestroyBoolExpr(e)
set HCDestinationTrig = null
set e = null
// (...)
endfunction
5. Reversing structs. I have a struct, and a unit that is its' member. Now i know have the unit variable, but i need to retrieve to what struct instance it belongs. Is there another way to accomplish that, other than looping through all struct instances and comparing their members to the variable?