My loop only runs once :S

shadowcon

New Member
Reaction score
4
JASS:
function Trig_Crush_PushEmBack takes nothing returns nothing
//Local variable declarations
//Units
local unit PickedUnit = GetEnumUnit()
local unit TriggeringUnit = GetTriggerUnit()
//Reals
local real Angle
//Locations
local location PickedUnitLoc = GetUnitLoc(PickedUnit)
local location TargetLoc = GetSpellTargetLoc()
local location pushbackedMinus200
//Loop Debug stuff
local boolean loccheck = false
local integer loopdebug = 0
//Declarations done
//Set the declared but not defined variables
set Angle = AngleBetweenPoints(TargetLoc, PickedUnitLoc)
set pushbackedMinus200= PolarProjectionBJ(TargetLoc, 200.00, Angle)
//Variables done
 //   call UnitDamageTargetBJ( TriggeringUnit, PickedUnit, 200.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED )
    call SetUnitPositionLocFacingLocBJ( PickedUnit, GetUnitLoc(PickedUnit), TargetLoc)
    loop
        exitwhen loccheck == true
        if (pushbackedMinus200 == GetUnitLoc(PickedUnit)) then
            set loccheck = true
            set loopdebug = loopdebug-1
        else
            set loopdebug = loopdebug+1
            call MoveUnitBack(loopdebug, PickedUnit, TargetLoc, Angle)
            call TriggerSleepAction(0.020)
            endif
    endloop
    
endfunction


here's the other functions that it calls;

JASS:
function PolarMinus5 takes real angle returns location
    local real x = GetLocationX(GetUnitLoc(GetEnumUnit())) + 5.00 * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(GetUnitLoc(GetEnumUnit())) + 5.00 * Sin(angle * bj_DEGTORAD)
    return Location(x, y)

endfunction

function MoveUnitBack takes integer loopdebug, unit PickedUnit, location TargetLoc, real Angle returns nothing
//Moves the unit back 5 distance and causes it to face the spell center
local location face = TargetLoc
local location loc = PolarMinus5(Angle)
    call SetUnitPositionLoc(PickedUnit, loc)
    call SetUnitFacing(PickedUnit, AngleBetweenPoints(loc, face))
    call DisplayTextToForce(GetPlayersAll(),I2S(loopdebug))
endfunction


okay, the trigger only runs MoveUnitBack once, I want it to run at least 20 times, call MoveUnitBack is in a loop that SHOULD run like 20 times, and not 1 time, what have I done wrong?
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Well, you kind of used TriggerSleepAction in the loop, which can malfunction in loops, and do crazy things.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
yea you should use a timer. Loops and sleepaction never works i have expirinced that many times before.
 

Azlier

Old World Ghost
Reaction score
461
[lJASS]TriggerSleepAction[/lJASS] works just fine in loops. Its inaccuracy and the way it has a minimum period makes it unusable for sliding and smooth effect, though.
 

shadowcon

New Member
Reaction score
4
if I use a timer I wouldn't be able to store local variables from one function to the timer expires trigger, then I would have to use globals and then it wouldnt be MUI right? or is there anyway to use hashtables to be able to avoid that?
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
[lJASS]GetEnumUnit()[/lJASS] only works on ForGroups, make sure you are calling your function with a ForGroup instead of a normal function call or something like that.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
there at polarminus5 use GetUnitX/Y because those locations leak and the UnitX/Y wont use locations and it will save a function call.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Am I the only one who saw this? [ljass]set loccheck = true [/ljass].
It's not looping because the [ljass]exitwhen[/ljass] has been met.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
am i the only on seeing the that is in an if block thast only met after like 20 times running the loop.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
It looks to me that the [ljass]if[/ljass] statement is initially true, but I can't get near a computer to test the code.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
me neither but i think thats not the reason. But i could be wrong my head is not good at running code.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
It has to be the reason.
Nothing else sets it's [ljass]exitwhen[/ljass] to true.
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Have you used some debug messages and checked if this if becomes true on first iteration or something like that?
JASS:
        if (pushbackedMinus200 == GetUnitLoc(PickedUnit)) then
            set loccheck = true
            set loopdebug = loopdebug-1



Edit -Just realized, if you are using ForGroup to call the function then you can't use TriggerSleepActions in the function so that might be the cause of the problem.
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
@J4L

It's actually pretty fun, the local needs ForGroup to not be null and the loop can't run using a ForGroup :D

Just decide what you want, if you still want to loop through all units in a group use a FirstOfGroup loop.

Here's how it looks (Hand coded so it might be some wrong arguments and function names):
JASS:

local group g = CreateGroup()
local unit u
call GroupAddGroup(g, source) // So you dont change anything in the normal group
set u = FirstOfGroup(g)
loop
    exitwhen u = null
    ..... // Do stuff with u
    call GroupRemoveUnit(g, u)
    set u = FirstOfGroup(g)
endloop
call DestroyGroup(g)
set g = null
set u = null
 

shadowcon

New Member
Reaction score
4
@everyone who wanted to test the code, i didnt add the entire trigger, only the what I thought was relevant part

@the one who thought that exitwhen was met, no, it wasn't met because it was supposed to check distance from a location and the unit affected was nowhere near it.

@Gwypaas, Yeah, the function was called using ForGroup so that with no wait inside it must been it
btw, I'm jass nub so I don't get what your function does... plz pm me in swedish :p
 

ZugZugZealot

New Member
Reaction score
33
It's not the loop that's screwed up per se.
[ljass]if (pushbackedMinus200 == GetUnitLoc(PickedUnit)) then[/ljass]
Is the problem to your code. Warcraft III can't do location comparisons.

Since there's a set amount of times it'll loop, you should just evaluate how many times it has looped instead.

(example, untested code)
JASS:
function Trig_Crush_PushEmBack takes nothing returns nothing
    local unit pickedUnit = GetEnumUnit()
    local unit trigUnit = GetTriggerUnit()
    
    local real x = GetUnitX(pickedUnit)
    local real y = GetUnitY(pickedUnit)
    local real angle = AngleBetweenXY( GetUnitX(trigUnit), GetUnitY(trigUnit), x, y, (GetUnitFacing(trigUnit)/180) * bj_PI, false)
    local integer i
    
    set i = 0
    loop
        exitwhen (i > 39)
        exitwhen (GetUnitState(pickedUnit, UNIT_STATE_LIFE) <= 0)
        set x = 5 * Cos(angle)
        set y = 5 * Sin(angle)
        exitwhen (IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
        call SetUnitPosition( pickedUnit, x, y)
        set i = i + 1
        call TriggerSleepAction(0.020)
    endloop
    
endfunction



Included function
JASS:
function AngleBetweenXY takes real x1, real y1, real x2, real y2, real default, boolean zRandom returns real
    local x = x2 - x1
    local y = y2 - y1
    
    if (y == 0.00) then
        if (x > 0.00) then
            return (0.00)
        elseif (x < 0.00) then
            return (bj_PI)
        else
            if (zRandom) then
                return (GetRandomReal(0.00, 2*bj_PI))
            else
                return (default)
            endif
        endif
    elseif (x == 0.00) then
        if (y > 0.00) then
            return (bj_PI * 0.50)
        else
            return (bj_PI * 1.50)
        endif
    endif
    return (Atan2(y,x))
endfunction
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
@ZugZugZealot

Sure that will cause bugs later but now that is NOT the problem, it will just return false. The only problem is that causing this functions thread to crash is the TriggerSleepAction. And your AngleBetweenXY is slow, bad coded and just contains useless stuff. You should use [ljass]call Atan2(y2-y, x2-x)[/ljass] directly instead of that shit.


@shadowcon

Ill try to send a working when I have enough time.
 

ZugZugZealot

New Member
Reaction score
33
I made it that way because for (y == 0) and x less than 0 because it would return 0. But somewhere down the line it looks like they fixed that.

Also, abrasive behavior is uncalled for in an assistance forum.

The main point of that was to get at was using a count for travel instead of position comparison.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top