HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Help] I don't know how to...

12-16-2007, 08:45 AM#1
Tide-Arc Ephemera
... optimize in Jass. As a matter of fact, I can't... and that's my life story.

Anyway. This trigger seems to only support roughly 5-6 units before killing itself. Could someone assist me in optimization of this?

Collapse JASS:
function Trig_Movement_Func001Func004002003001 takes nothing returns boolean
    return ( GetFilterUnit() != udg_Ball[GetForLoopIndexA()] )
endfunction

function Trig_Movement_Func001Func004002003002 takes nothing returns boolean
    return ( GetFilterUnit() != gg_unit_Hmkg_0012 )
endfunction

function Trig_Movement_Func001Func004002003 takes nothing returns boolean
    return GetBooleanAnd( Trig_Movement_Func001Func004002003001(), Trig_Movement_Func001Func004002003002() )
endfunction

function Trig_Movement_Func001Func005A takes nothing returns nothing
    set udg_Point[1] = GetUnitLoc(GetEnumUnit())
    call AddSpecialEffectLocBJ( udg_Point[1], "Abilities\\Weapons\\GryphonRiderMissile\\GryphonRiderMissileTarget.mdl" )
    call DestroyEffect( GetLastCreatedEffectBJ() )
    call RemoveLocation( udg_Point[1] )
    set udg_Ang[GetUnitUserData(GetEnumUnit())] = AngleBetweenPoints(GetUnitLoc(GetEnumUnit()), GetUnitLoc(udg_Ball[GetForLoopIndexA()]))
    set udg_Ang[GetUnitUserData(udg_Ball[GetForLoopIndexA()])] = AngleBetweenPoints(GetUnitLoc(udg_Ball[GetForLoopIndexA()]), GetUnitLoc(GetEnumUnit()))
    set udg_Speed[GetUnitUserData(udg_Ball[GetForLoopIndexA()])] = ( ( udg_Speed[GetUnitUserData(udg_Ball[GetForLoopIndexA()])] / 2.00 ) - ModuloReal(( udg_Speed[GetUnitUserData(udg_Ball[GetForLoopIndexA()])] / 2.00 ), 1.00) )
    set udg_Speed[GetUnitUserData(GetEnumUnit())] = udg_Speed[GetUnitUserData(udg_Ball[GetForLoopIndexA()])]
    set udg_Anim_Speed[GetUnitUserData(GetEnumUnit())] = ( 20.00 * udg_Speed[GetUnitUserData(GetEnumUnit())] )
    call SetUnitTimeScalePercent( udg_Ball[GetUnitUserData(GetEnumUnit())], udg_Anim_Speed[GetUnitUserData(GetEnumUnit())] )
    set udg_Anim_Speed[GetUnitUserData(udg_Ball[GetForLoopIndexA()])] = ( 20.00 * udg_Speed[GetUnitUserData(GetEnumUnit())] )
    call SetUnitTimeScalePercent( udg_Ball[GetUnitUserData(udg_Ball[GetForLoopIndexA()])], udg_Anim_Speed[GetUnitUserData(udg_Ball[GetForLoopIndexA()])] )
    set udg_Point[1] = PolarProjectionBJ(GetUnitLoc(udg_Ball[GetForLoopIndexA()]), 60.00, udg_Ang[GetForLoopIndexA()])
    call SetUnitPositionLocFacingBJ( udg_Ball[GetForLoopIndexA()], udg_Point[1], udg_Ang[GetForLoopIndexA()] )
    call RemoveLocation( udg_Point[1] )
    set udg_Point[1] = PolarProjectionBJ(GetUnitLoc(GetEnumUnit()), 60.00, udg_Ang[GetUnitUserData(GetEnumUnit())])
    call SetUnitPositionLocFacingBJ( udg_Ball[GetUnitUserData(GetEnumUnit())], udg_Point[1], udg_Ang[GetForLoopIndexA()] )
    call RemoveLocation( udg_Point[1] )
endfunction

function Trig_Movement_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = udg_Num
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Point[1] = PolarProjectionBJ(GetUnitLoc(udg_Ball[GetForLoopIndexA()]), udg_Speed[GetForLoopIndexA()], udg_Ang[GetForLoopIndexA()])
        call SetUnitPositionLocFacingBJ( udg_Ball[GetForLoopIndexA()], udg_Point[1], udg_Ang[GetForLoopIndexA()] )
        call RemoveLocation( udg_Point[1] )
        set udg_UnitGroup[1] = GetUnitsInRangeOfLocMatching(50.00, GetUnitLoc(udg_Ball[GetForLoopIndexA()]), Condition(function Trig_Movement_Func001Func004002003))
        call ForGroupBJ( udg_UnitGroup[1], function Trig_Movement_Func001Func005A )
        call DestroyGroup( udg_UnitGroup[1] )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Movement takes nothing returns nothing
    set gg_trg_Movement = CreateTrigger(  )
    call DisableTrigger( gg_trg_Movement )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Movement, 0.01 )
    call TriggerAddAction( gg_trg_Movement, function Trig_Movement_Actions )
endfunction



If it looks funny, that's because this is a trigger that's been derived from GUI.

So um, does anyone have any ideas that could assist me in optimization?
12-16-2007, 09:25 AM#2
cohadar
It is simple, use local integer variable instead of bj_forLoopAIndex

(NEVER USE bj_forLoopAIndex in JASS)

Collapse JASS:
function Trig_Movement_Filter takes nothing returns boolean
    reurn (GetFilterUnit() != udg_Ball[udg_TempInt]) and ( GetFilterUnit() != gg_unit_Hmkg_0012 )
endfunction

function Trig_Movement_Enum takes nothing returns nothing
    set udg_Point[1] = GetUnitLoc(GetEnumUnit())
    call AddSpecialEffectLocBJ( udg_Point[1], "Abilities\\Weapons\\GryphonRiderMissile\\GryphonRiderMissileTarget.mdl" )
    call DestroyEffect( GetLastCreatedEffectBJ() )
    call RemoveLocation( udg_Point[1] )
    set udg_Ang[GetUnitUserData(GetEnumUnit())] = AngleBetweenPoints(GetUnitLoc(GetEnumUnit()), GetUnitLoc(udg_Ball[udg_TempInt]))
    set udg_Ang[GetUnitUserData(udg_Ball[udg_TempInt])] = AngleBetweenPoints(GetUnitLoc(udg_Ball[udg_TempInt]), GetUnitLoc(GetEnumUnit()))
    set udg_Speed[GetUnitUserData(udg_Ball[udg_TempInt])] = ( ( udg_Speed[GetUnitUserData(udg_Ball[udg_TempInt])] / 2.00 ) - ModuloReal(( udg_Speed[GetUnitUserData(udg_Ball[udg_TempInt])] / 2.00 ), 1.00) )
    set udg_Speed[GetUnitUserData(GetEnumUnit())] = udg_Speed[GetUnitUserData(udg_Ball[udg_TempInt])]
    set udg_Anim_Speed[GetUnitUserData(GetEnumUnit())] = ( 20.00 * udg_Speed[GetUnitUserData(GetEnumUnit())] )
    call SetUnitTimeScalePercent( udg_Ball[GetUnitUserData(GetEnumUnit())], udg_Anim_Speed[GetUnitUserData(GetEnumUnit())] )
    set udg_Anim_Speed[GetUnitUserData(udg_Ball[udg_TempInt])] = ( 20.00 * udg_Speed[GetUnitUserData(GetEnumUnit())] )
    call SetUnitTimeScalePercent( udg_Ball[GetUnitUserData(udg_Ball[udg_TempInt])], udg_Anim_Speed[GetUnitUserData(udg_Ball[udg_TempInt])] )
    set udg_Point[1] = PolarProjectionBJ(GetUnitLoc(udg_Ball[udg_TempInt]), 60.00, udg_Ang[udg_TempInt])
    call SetUnitPositionLocFacingBJ( udg_Ball[udg_TempInt], udg_Point[1], udg_Ang[udg_TempInt] )
    call RemoveLocation( udg_Point[1] )
    set udg_Point[1] = PolarProjectionBJ(GetUnitLoc(GetEnumUnit()), 60.00, udg_Ang[GetUnitUserData(GetEnumUnit())])
    call SetUnitPositionLocFacingBJ( udg_Ball[GetUnitUserData(GetEnumUnit())], udg_Point[1], udg_Ang[udg_TempInt] )
    call RemoveLocation( udg_Point[1] )
endfunction

function Trig_Movement_Actions takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > udg_Num
        set udg_Point[1] = PolarProjectionBJ(GetUnitLoc(udg_Ball[i]), udg_Speed[i], udg_Ang[i])
        call SetUnitPositionLocFacingBJ( udg_Ball[i], udg_Point[1], udg_Ang[i] )
        call RemoveLocation( udg_Point[1] )
        set udg_TempInt = i
        set udg_UnitGroup[1] = GetUnitsInRangeOfLocMatching(50.00, GetUnitLoc(udg_Ball[i]), Condition(function Trig_Movement_Filter))
        call ForGroupBJ( udg_UnitGroup[1], function Trig_Movement_Enum )
        call DestroyGroup( udg_UnitGroup[1] )
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Movement takes nothing returns nothing
    set gg_trg_Movement = CreateTrigger(  )
    call DisableTrigger( gg_trg_Movement )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Movement, 0.01 )
    call TriggerAddAction( gg_trg_Movement, function Trig_Movement_Actions )
endfunction



12-17-2007, 04:13 AM#3
Tide-Arc Ephemera
Was this vJass'd? Because here's the list of errors it gave me:
- Expected a code statement
- Invalid type for specified operator
- Expected a name
- Expected a name
- Expected a name
- Expected a name
- Expected a name
- Expected a name
- Expected a name
- Expected a name
- Expected a name
- Expected a code statement
- Expected a code statement
- Expected a code statement
- Expected a name
- Expected a name
- Expected a name
- Expected a variable name
- Expected a name
- Expected a function name
- Expected a variable name
- Expected "endloop"
- Expected "endloop"
- Expected a function name
- Expected "endloop"
12-17-2007, 06:42 AM#4
cohadar
No it wasn't vJass'd I was very careful about that.
I just worked in jasscraft so I could not really compile it.

Btw the best way to learn jass is not to start converting complicated triggers,
but creating only a basic trigger with event and condition, converting that and doing the rest in jass.

There is nothing harder than converting a huge GUI trigger to jass.
If you want to learn jass, start from jass, not from gui.
12-17-2007, 06:56 AM#5
Pyrogasm
He spelled "return" wrong in the second line of the trigger.
12-17-2007, 07:44 AM#6
Tide-Arc Ephemera
Holy flu-nucking shit, that 1 fucking letter made 15135487415 errors worth of difference.
+Rep to Pyro for his eyes
+Rep to Cohadar for his good work!
12-17-2007, 08:09 AM#7
Pyrogasm
One more reason to hate the default Syntax Checker.