# Help with rect script (JASS and GUI)

Status
Not open for further replies.

#### streetpunk

Level 11
So I use this rect script in my project, it picks units whithin a rect (Loc1 and Loc2) then do damage to them, but recently I noticed that if I do the actions within about 5 seconds game time, then the action is not run, and will not be run if the action is done again. What I wanted is to ask someone to take a look to see if there's anything wrong with the script.

Code:
``````//TESH.scrollpos=6
//TESH.alwaysfold=0
function LSE_GroupEnumUnitsInRangeOfSegment takes group whichgroup, real Ax, real Ay, real Bx, real By, real distance returns nothing
local real dx = Bx-Ax
local real dy = By-Ay
local real L = ((dx)*(dx) + (dy)*(dy)) // Get quasi length
local real r = SquareRoot(dx*dx+dy*dy)/2+distance + udg_LSE_MaxUnitCollision // replace 400.0 with the max collision size in your map
local unit u
local group g = CreateGroup()
call GroupClear(whichgroup)
call GroupEnumUnitsInRange(g, Ax+(dx/2), Ay+(dy/2), r, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if L == 0 and IsUnitInRangeXY(u, Ax, Ay, distance) then // seg is actually a point so lets return the point
else
set r = ((GetUnitX(u)-Ax)*(dx) + (GetUnitY(u)-Ay)*(dy))/(L) // get the ratio
if r > 1 then // split if/thens so that it exists properly
if IsUnitInRangeXY(u, Bx, By, distance) then // closests point is past seg, so return end point B
endif
elseif r < 0 then
if IsUnitInRangeXY(u, Ax, Ay, distance) then // same as B, but at A instead
endif
elseif IsUnitInRangeXY(u, Ax+r*(dx), Ay+r*(dy), distance) then // In the middle of A and B so use the ratio to find the point
endif
endif
call GroupRemoveUnit(g, u)
endloop
call DestroyGroup(g)
set g = null
endfunction

function Trig_LSE_Run_Units_Actions takes nothing returns nothing
call LSE_GroupEnumUnitsInRangeOfSegment(udg_LSE_Group, GetLocationX(udg_LSE_Loc_1), GetLocationY(udg_LSE_Loc_1), GetLocationX(udg_LSE_Loc_2), GetLocationY(udg_LSE_Loc_2), udg_LSE_Width)
endfunction

//===========================================================================
function InitTrig_LSE_Get_Units takes nothing returns nothing
set gg_trg_LSE_Get_Units = CreateTrigger(  )
call TriggerAddAction( gg_trg_LSE_Get_Units, function Trig_LSE_Run_Units_Actions )
endfunction``````

When I try to do actions to units in LSE_Group (I run the trigger LSE_Units) they will only work if about five seconds of game have passed, otherwise it will glitch the action and it is not possible to do them again.

#### Jampion

Level 15
The trigger seems fine to me. I did not look at the math behind it, but I found nothing that would cause the problem you have.
Maybe the variables you are using this function with are not initialized when calling this function.
If you are using an array of unit groups you must first create a unit group, before you can units to it.
If you are using for example UnitGroupA[2] as a variable in the variable editor, only UnitGroupA[0] and UnitGroupA[1] are initialized.

#### streetpunk

Level 11
Is it in vJass? If so, you mind translate it to normal JASS, please?

#### streetpunk

Level 11
I solved this rect problem or well... it solved itself as I did nothing to it and one day it got back to working running just fine lol

Status
Not open for further replies.

Replies
7
Views
801
Replies
10
Views
634
Replies
6
Views
610
Replies
1
Views
907
Replies
2
Views
785