• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] ForGroupBJ issues

Status
Not open for further replies.
Level 7
Joined
Jun 16, 2008
Messages
253
I'm having trouble with using Destroy group and remove Rect etc in reawltion to a ForGroupBJ function. Basically the triggers look like this.

function func1 takes nothing returns nothing
local unit u = GetEnumUnit()
local integer i = GetUnitUserData(u)
local location l = GetUnitLoc(u)
call Something to do with u,i and l.
call RemoveLocation(l)
set l = null
set u = null
set i = 0
endfunction

function actions takes nothing returns nothing
local rect r = GetPlayableMapRect()
local group g = GetEnumUnitsInRect(r) //Or something like that.
call ForGroupBJ(g, (function func1))
call DestroyGroup(g)
set g = null
call RemoveRect(r)
set r = null
endfunction


function InitTrig...
(Periodic (0.01))
endfunction

Now it works fine if I don't remove location or rects or groups, but just use nulls, but I don't know the effect on memory. But if I put all the Removes and Destroys in, then the trigger completely stuffs up, as if I was removing and Destroying before calling the function. But that shouldn't happen should it?
Rect and Group should only be Removed after the whole ForGroupBJ has finished, and I thought ForGroupBJ was some kind of loop, that executed func1 for every picked unit, so that even if I removed the location at the end, it would recreate it at the beginning of the next loop for the next unit.

Could someone tell me why this is not so? I want to clean up the memory leaks of my map. :(
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Most likely since you're destroying bj_mapInitialPlayableArea (GetPlayableMapRect() just returns that).

Either way, use ForGroup and not ForGroupBJ. The parameters are right for the former.

Also, in the future, wrap your code in [code=jass]code[/code] to get all the syntax highlighting, indenting, and such.
 
Level 7
Joined
Jun 16, 2008
Messages
253
Ahk. I managed to get that trigger working fine now, and I imagine it was like you say (I suspected it was something like that, just didn't know it was possible. :D)

I'm actually having quite a lot of problems with groups and the like.

For example, I have a function called serve_drinks, and it uses I think three groups.

Actually, I'm going to post up the code. Be right back...

(Several minutes later...)

JASS:
function GetThirstyPatrons takes unit uu returns group
    local unit u = uu
    local integer ui = GetUnitUserData(u)
    local group gg = CreateGroup( )
    local integer amnt = CountUnitsInGroup(udg_Target_Group[ui])
    local integer i = 0
    set gg = udg_Target_Group[ui]
loop
exitwhen i > amnt
    if udg_Thirsty[GetUnitUserData(FirstOfGroup(gg))] != true then
    call GroupRemoveUnit(gg, FirstOfGroup(gg))
    else
    endif
    set i = i + 1
endloop
    return gg
endfunction



JASS:
function serve_drinks takes unit uu, real tstrr returns nothing
    local unit u = uu
    local integer ui = GetUnitUserData(u)
    local integer op = 0
    local group g = CreateGroup()
    local unit gu = null
    local integer cu = 0
    local real tstr = tstrr
    call DisplayTextToPlayer(Player(0), 100, 100, "Serving Drinks!")
loop
exitwhen udg_Currentthought[ui] != "serve_drinks" or op >= 10000
    call DisplayTextToPlayer(Player(0), 100, 100, "1")
    call GroupAddGroup(GetThirstyPatrons(u), g)
    set cu = CountUnitsInGroup(g)
    set gu = FirstOfGroup(g)
if cu > 0 then
    call DisplayTextToPlayer(Player(0), 100, 100, "cu>0")
    if UnitHasItemOfTypeBJ(u, 'dkfw') == true then //dkfw is Keg of Thunderwater.
        if DistanceBetweenPoints(GetUnitLoc(u), GetUnitLoc(gu)) <= 150 then
        call UnitAddItemSwapped( GetItemOfTypeFromUnitBJ(u, 'dkfw'), gu )
        else
        call DisplayTextToPlayer(Player(0), 100, 100, "Should be giving ale to unit.")
        call IssuePointOrder(u, "move", GetUnitX(gu), GetUnitY(gu))
        endif
    else
    call DisplayTextToPlayer(Player(0), 100, 100, "Should be getting ale.")
    call IssueTargetOrder( u, "smart", RandomItemInRectBJ(gg_rct_Kitchen, Condition(function True_AI_Condition) ))
    endif
    //call GroupRemoveUnit(g, gu)
    //set cu = cu - 1
else
endif
    call GroupRemoveGroup(g, g)
    set cu = 0
    set op = op + 1
    call TriggerSleepAction(0.5)
endloop
    if udg_Currentthought[ui] == "serve_drinks" then
    call DisplayTextToPlayer(Player(0), 100, 100, "Serving Drinks Again!")
    call serve_drinks.execute(u, tstr)
    else
    call DisplayTextToPlayer(Player(0), 100, 100, "Stopped Serving Drinks!")
endif
endfunction

Those are the two important functions, serve_drinks is run off a larger AI (as serve_drinks.execute(u, tstr)) but that shouldn't be affecting it, I know the loop is going anyway.

For clarification, u is the unit that is using the AI for his brain. Tstr, is the strength of the thought (in this case, serve_drinks).


udg_Target_group is a variable, it will be the units 'targets' basically any unit around it.

The problem seems to be that in serve drinks, when it CountUnitsInGroup(g), it doesn't count any (apparently), because the little message inside the (if cu>0 then) never displays, it justs goes "1" every time to show me it's working.

It used to work yesterday, could someone tell me why it doesn't now?
 
Status
Not open for further replies.
Top