Why isn't this loop working?

Cokemonkey11

New Member
Reaction score
18
Or perhaps a better question, why isn't the function with the loop being called correctly?

JASS:

function moveInCircle takes unit centerUnit, unit rifleAttacker, unit footAttacked returns nothing
    local integer i = 0
    local location posCenter = GetUnitLoc(centerUnit)
    local location posCenterOff
    local real posRifleOffX
    local real posRifleOffY
    local location posCenterOff2
    local real posFootOffX
    local real posFootOffY
    loop
        exitwhen i > 359
        set i = i+1
        set posCenterOff = PolarProjectionBJ(posCenter,512,i)
        set posRifleOffX = GetLocationX(posCenterOff)
        set posRifleOffY = GetLocationY(posCenterOff)
        set posCenterOff2 = PolarProjectionBJ(posCenter,450,i)
        set posFootOffX = GetLocationX(posCenterOff2)
        set posFootOffY = GetLocationY(posCenterOff2)
        call SetUnitX(rifleAttacker,posRifleOffX)
        call SetUnitY(rifleAttacker,posRifleOffY)
        call SetUnitX(footAttacked,posFootOffX)
        call SetUnitY(footAttacked,posFootOffY)
        call TriggerSleepAction(.1)
    endloop
endfunction

function Trig_dummyCenter_Actions takes nothing returns nothing
    local unit centerUnit
    local unit rifleAttacker
    local unit footAttacked
    call CreateUnitAtLoc(Player(0),'hfoo',GetRectCenter(GetPlayableMapRect()),270)
    set centerUnit = GetLastCreatedUnit()
    call CreateUnitAtLoc(Player(15),'hrif',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),512,0),270)
    set rifleAttacker = GetLastCreatedUnit()
    call CreateUnitAtLoc(Player(15),'hfoo',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),390,0),270)
    set footAttacked = GetLastCreatedUnit()
    call IssueTargetOrder(rifleAttacker,"attack",footAttacked)
    call moveInCircle(centerUnit,rifleAttacker,footAttacked)
endfunction

function InitTrig_dummyCenter takes nothing returns nothing
    set gg_trg_dummyCenter = CreateTrigger()
    call TriggerRegisterTimerEventSingle(gg_trg_dummyCenter,3)
    call TriggerAddAction(gg_trg_dummyCenter, function Trig_dummyCenter_Actions)
endfunction
 

saw792

Is known to say things. That is all.
Reaction score
280
Few things... You are using leaking locations in your function with the loop. There is no need to use locations at all anyway, you can simply use GetUnitX and GetUnitY and project with cos and sin. Why do you have a wait in your loop? It shouldn't hit the op limit with only 360 repititions.

The way to run small increments is to use a timer, not a wait.
 

Cokemonkey11

New Member
Reaction score
18
Thank you for telling me what I know, but can you tell me what's preventing it from working?

I know how to use periodics to use a number less than .1 (for >10 fps) and i know how to fix leaks.

I don't care about that right now I just need a proof of concept, but it won't happen unless the loop runs.
 

saw792

Is known to say things. That is all.
Reaction score
280
It would be about 8 times faster to do it the correct way, with timers and reals but anyway if you say you know...

The reason it isn't working is because CreateUnitAtLoc doesn't save the last created unit. Change it to:
JASS:
function Trig_dummyCenter_Actions takes nothing returns nothing
    local unit centerUnit
    local unit rifleAttacker
    local unit footAttacked
    set centerUnit = CreateUnitAtLoc(Player(0),'hfoo',GetRectCenter(GetPlayableMapRect()),270)
    set rifleAttacker = CreateUnitAtLoc(Player(15),'hrif',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),512,0),270)
    set footAttacked = CreateUnitAtLoc(Player(15),'hfoo',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),390,0),270)
    call IssueTargetOrder(rifleAttacker,"attack",footAttacked)
    call moveInCircle(centerUnit,rifleAttacker,footAttacked)
endfunction


It looks terrible anyway, the unit's collision stuffs it up.
 
Reaction score
333
Thank you for telling me what I know, but can you tell me what's preventing it from working?

I know how to use periodics to use a number less than .1 (for >10 fps) and i know how to fix leaks.

I don't care about that right now I just need a proof of concept, but it won't happen unless the loop runs.

It is not enough to know how to do something, you must also know to do it. TriggerSleepAction, in general, sucks and also bugs up in group and timer callbacks and trigger conditions.

At a glance I see nothing that would cause the code to function incorrectly, so you should probably sprinkle your code with BJDebugMsg calls to see how far into the function (or loop) you actually progress. Put something like BJDebugMsg("d"+I2S(i)) in the loop and see what happens.
 

Cokemonkey11

New Member
Reaction score
18
It would be about 8 times faster to do it the correct way, with timers and reals but anyway if you say you know...

The reason it isn't working is because CreateUnitAtLoc doesn't save the last created unit. Change it to:
JASS:
function Trig_dummyCenter_Actions takes nothing returns nothing
    local unit centerUnit
    local unit rifleAttacker
    local unit footAttacked
    set centerUnit = CreateUnitAtLoc(Player(0),'hfoo',GetRectCenter(GetPlayableMapRect()),270)
    set rifleAttacker = CreateUnitAtLoc(Player(15),'hrif',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),512,0),270)
    set footAttacked = CreateUnitAtLoc(Player(15),'hfoo',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),390,0),270)
    call IssueTargetOrder(rifleAttacker,"attack",footAttacked)
    call moveInCircle(centerUnit,rifleAttacker,footAttacked)
endfunction


It looks terrible anyway, the unit's collision stuffs it up.

Thank you you're a gentleman and a scholar; using set var to create unit worked perfectly.

Now I can get on to making it work at >10 fps and fix my leaks.

Plus reps for you of course.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top