HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Most Efficient?

05-19-2006, 12:07 PM#1
Thunder_Eye
What is most efficient?
I would think example 2.
example 1:
Actions
Set unit[1] = Footman 0001 <gen>
Set unit[2] = Footman 0011 <gen>
Set unit[3] = Footman 0012 <gen>
Collapse For each (Integer A) from 1 to 3, do (Actions)
Collapse Loop - Actions
Unit - Kill unit[(Integer A)]
example 2:
Actions
Unit - Kill Footman 0001 <gen>
Unit - Kill Footman 0011 <gen>
Unit - Kill Footman 0012 <gen>
05-19-2006, 12:09 PM#2
Blade.dk
2nd example.

In the first example you first save the contents of 3 variables in 3 different array slots, and then loop through the array killing the units. Just 3 times KillUnit without the loop is better, as it won't have to set variables (GUI loops also uses variables).
05-19-2006, 12:09 PM#3
Thunder_Eye
So this means that going through a loop to for example move a unit around another using the degree as a real variable is worse then moving the unit as in example 2?

but in a case like this one below, its better to use a loop I assume? or is it? cause I do one call and one "set variable" instead of just one call. Thou I save some space.
example 3:
Actions
Set realvar = 0.00
Collapse For each (Integer A) from 1 to 36, do (Actions)
Collapse Loop - Actions
Unit - Move Footman 0001 <gen> instantly to ((Position of (Triggering unit)) offset by 100.00 towards realvar degrees)
Set realvar = (realvar + 10.00)

But then this would be the best:
Collapse JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local integer a = 1
    loop
        exitwhen a > 36
        call SetUnitPositionLoc( gg_unit_hfoo_0001, PolarProjectionBJ(GetUnitLoc(GetTriggerUnit()), 100.00, I2R(a * 10)) )
        set a = a + 1
    endloop
endfunction
05-19-2006, 12:24 PM#4
BertTheJasser
Yes, it would be best, but the code obove leaks as hell. 36*2 locations which are never removed.
05-19-2006, 01:19 PM#5
Thunder_Eye
I know :P
05-19-2006, 01:34 PM#6
bounty_hunter2
second one
05-19-2006, 02:06 PM#7
Vexorian
exactly why would the second be better? the only reason I could think about is that it uses local JASS loop instead of GUI's for loop . But besides of that both seem pretty unefficient.

I2R(a * 10)

No need at all for the I2R

Not a lot of difference between increasing the real and making the product everytime.

Collapse JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local real a = 10
    loop
        exitwhen a > 360


        call SetUnitPositionLoc( gg_unit_hfoo_0001, PolarProjectionBJ(GetUnitLoc(GetTriggerUnit()), 100.00, a) )
        set a = a + 10
    endloop
endfunction

Of course, the whole function is absurd, besides of the leaks this function wouldn't really work.
05-19-2006, 02:12 PM#8
Thunder_Eye
so when a function takes a real as argument I can aswell give it a integer?
EDIT: Oh wait just noticed you used a real in the loop : P
05-19-2006, 02:18 PM#9
Vexorian
you can use integers where reals are required. Unless you are in a return value. (Don't ask why)

one thing to note though is that some times you need R2I to ensure that real division will be done

Collapse JASS:
 local integer a=1
 local integer b=3

  local real c = a/b //result is 0.00
  local real e = I2R(a/b) //result is 0.00
  local real d = I2R(a)/b //result is 0.3333333

05-19-2006, 02:20 PM#10
Thunder_Eye
Collapse JASS:
  local real d = a/R2I(b) //result is 0.00
?
05-19-2006, 02:22 PM#11
Vexorian
what?

If any of them is a real then it will be real division otherwise it will be integer divisision
05-19-2006, 02:28 PM#12
Thunder_Eye
ok