HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Looping Question

02-04-2008, 03:10 PM#1
Tastingo
Ok so for my map I have a local location and group created at the beginning. After that I have a loop that loops through and sets the group and location for the looped Player(a). At the last line, of the loop, should i destroy the group and location or should I do that at the end of the whole function. If I destroy the group in the loop, will it just remove the information from the group or just destroy the whole group permantley? (Same question for location)

Collapse JASS:
    loop
        call GroupEnumUnitsOfPlayer(g, Player(a), m)
        set l3 = GetUnitLoc(FirstOfGroup(g))
            if(GetLocalPlayer() == Player(a)) then
                call PanCameraToTimed(GetLocationX(l3), GetLocationY(l3), 1.0)
            endif
        set a = a+1
        call RemoveLocation(l3)
        call DestroyGroup(g)
    exitwhen a>11
    endloop
02-04-2008, 03:51 PM#2
Captain Griffen
It'll destroy the whole group.

Clear the group at the end of the loop, and destroy it outside the loop.
02-04-2008, 05:29 PM#3
Tastingo
ty, what about locations. Also when I'm destroying groups should I always clear them first?
02-04-2008, 05:54 PM#4
Fireeye
Best way is of course not using / recycling variables, i made the work rewritting your trigger part.
I replaced the location with x and y values and recycled the Group.
Collapse JASS:
globals
    group PickGroup = CreateGroup()
endglobals

function x takes nothing returns nothing
    local integer i = 0
    local real x = 0.
    local real y = 0.
    local unit u = null
    loop
        exitwhen i > 11
        call GroupEnumUnitsOfPlayer(PickGroup,Player(i),null)
        set u = FirstOfGroup(PickGroup)
        set x = GetUnitX(u)
        set y = GetUnitY(u)
        if GetLocalPlayer() == Player(i) then
            call PanCameraToTimed(x,y,1.0)
        endif
        call GroupClear(PickGroup)
        set i = i + 1
    endloop
    set u = null
endfunction
02-04-2008, 09:06 PM#5
Tastingo
ty for helping. Fire i will pm u for more help, since it wont be on topic. if its ok with u
02-05-2008, 12:01 AM#6
Pyrogasm
You can just post in the thread... maybe someone else can help you if Fireeye can't.
02-06-2008, 04:46 PM#7
Tastingo
Collapse JASS:
function Remove takes nothing returns nothing
call RemoveUnit(GetEnumUnit())
endfunction

Collapse JASS:
local integer a = 0
local group all = CreateGroup()
    loop
        exitwhen a > 11
        call GroupEnumUnitsOfPlayer(all,Player(a),null)
        set a = a + 1
    endloop
call ForGroup(all, function Remove)

I previouslly changed some of my scripting to the way I saw fire do that loop for me. The loop is supposed to add all the units of each player into a group of all the units. Seemed more convenient then making a group for each player and then adding all the groups to one group. For some reason it isn't removing all the units from the game. Does it have something to do with the loop or the other function/script? If you could please help, please do. Also are there any leaks with doing the loop the way I did it?
02-06-2008, 05:52 PM#8
TaintedReality
Use GroupEnumUnitsInRect(all,bj_mapInitialPlayableArea,null) instead of adding all units owned by each player.
02-06-2008, 07:14 PM#9
Tastingo
cool thank you, that helped. I honestly love these forums, don't think I would of been able to learn any JASS without it.