• 🏆 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!

Unit Group being cleared after the trigger!

Status
Not open for further replies.
Level 6
Joined
Jun 20, 2005
Messages
108
Hello everyone.

I'm having a problem with a new trigger I'm doing. It's supposed to spawm two units from a preset array and make them fight each other. When one of them wins, the trigger must spawn other 2 units (there are not the same as before) and repeat itself until there's no unit to spawn in the preset group, then it resets.

The problem is that when I use a unit on this trigger, I add it to another group (udg_GROUP_Duel[2]), but for some reason when the trigger runs again, that group is empty! I don't use this group in any other function and I'm totally lost with this bug. Could you guys help me?

Thanks in advance.

Here's the code (Full of debug messages trying to track the bug):

JASS:
function Trig_Spawn_Duelists_Actions takes nothing returns nothing
    local unit u1
    local unit u2
    local unit u
    local location loc
    call DisplayTextToForce(udg_GROUP_Debug, "start")    
    if ( CountUnitsInGroup(udg_GROUP_Duel[1]) > 1 ) then
        //unit on the left
        call DisplayTextToForce(udg_GROUP_Debug, "Before all: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
        set loc = GetRectCenter(gg_rct_Duel_Arena_1)
        set u = GroupPickRandomUnit(udg_GROUP_Duel[1])
        set u1 = CreateUnitAtLoc(Player(PLAYER_NEUTRAL_PASSIVE), GetUnitTypeId(u), loc, 0.00)
        call DisplayTextToForce(udg_GROUP_Debug, "u1 picked: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
        call GroupAddUnit( udg_GROUP_Duel[2], u1 )
        call GroupRemoveUnit( udg_GROUP_Duel[1], u )
        call DisplayTextToForce(udg_GROUP_Debug, "After Removing u1: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
        call Leak_SFX(loc,"Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl") 
        call SetUnitAnimation( u1, "stand victory" )
        //unit on the right        
        set loc = GetRectCenter(gg_rct_Duel_Arena_2)
        set u = GroupPickRandomUnit(udg_GROUP_Duel[1])
        set u2 = CreateUnitAtLoc(Player(PLAYER_NEUTRAL_PASSIVE), GetUnitTypeId(u), loc, 180.00)
        call DisplayTextToForce(udg_GROUP_Debug, "u2 Picked: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
        call GroupAddUnit( udg_GROUP_Duel[2], u2 )
        call GroupRemoveUnit( udg_GROUP_Duel[1], u )
        call Leak_SFX(loc,"Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl") 
        call SetUnitAnimation( u2, "stand victory" )
        call TriggerSleepAction( 3.00 )
        call IssueTargetOrderBJ( u1, "attack", u2 )
        call IssueTargetOrderBJ( u2, "attack", u1 )
        call DisplayTextToForce(udg_GROUP_Debug, "After all: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
    else
        call DisplayTextToForce(udg_GROUP_Debug, "Else: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
        call GroupAddGroup( udg_GROUP_Duel[2], udg_GROUP_Duel[1] )
        call DisplayTextToForce(udg_GROUP_Debug, "Group Added")
        call GroupClear( udg_GROUP_Duel[2] )
        call DisplayTextToForce(udg_GROUP_Debug, "Group Cleared")
        call DisplayTextToForce(udg_GROUP_Debug, "Else Checking: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
       // call TriggerExecute( gg_trg_Spawn_Duelists )
    endif
    //set u = null
    //set u1 = null
    //set u2 = null
    //call RemoveLocation(loc)
    //set loc = null
    call DisplayTextToForce(udg_GROUP_Debug, "Last Check: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))

endfunction
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Does this make it easier?:

JASS:
constant function Telepath takes nothing returns string
    return "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl"
endfunction
 
function NewDuelist takes rect r, unit u returns unit
    set u=CreateUnit(Player(15),udg_Duelist[GetRandomInt(0,3)],GetRectCenterX(r),GetRectCenterY(r),0)
    call DestroyEffect(AddSpecialEffectTarget( Telepath() , u , "origin" )) 
    call SetUnitAnimation( u , "stand victory" )
    return u
endfunction
 
function Trig_Spawn_Duelists_Actions takes nothing returns nothing
    local unit u1=NewDuelist( gg_rct_Duel_Arena_1 , bj_lastCreatedUnit )
    local unit u2=NewDuelist( gg_rct_Duel_Arena_2 , bj_lastCreatedUnit )
    call TriggerSleepAction(3)
    call IssueTargetOrder( u1 , "attack" , u2 )
    call IssueTargetOrder( u2 , "attack" , u1 )
    set u1=null
    set u2=null
endfunction
 
Last edited:
Level 6
Joined
Jun 20, 2005
Messages
108
The spawning trigger is included in my Unit Preloading trigger, here it is:

JASS:
    set u = CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), 'h00A', L_POINT, 0.00 )
    call GroupAddUnit( udg_GROUP_Duel[1], u )
    call ShowUnitHide( u )
    set u = CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), 'h00B', L_POINT, 0.00 )
    call GroupAddUnit( udg_GROUP_Duel[1], u )
    call ShowUnitHide( u )
    set u = CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), 'h00C', L_POINT, 0.00 )
    call GroupAddUnit( udg_GROUP_Duel[1], u )
    call ShowUnitHide( u )
    set u = CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), 'h00D', L_POINT, 0.00 )
    call GroupAddUnit( udg_GROUP_Duel[1], u )
    call ShowUnitHide( u )

It doesn't have any conditions and is triggered at map init.

and I'm using regular editor.
 
I was thinking about the else, if the units in Group[1] is not greater than one, you add all units of Group[1] into Group[2] but clears Group[2] right after....

JASS:
 else
        call DisplayTextToForce(udg_GROUP_Debug, "Else: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
        //Here you add Group[1] to Group[2] because if my syntax is right the first parameter is the group that will get the additional units and the second parameter is the group where the units will come from
        call GroupAddGroup( udg_GROUP_Duel[2], udg_GROUP_Duel[1] )
        call DisplayTextToForce(udg_GROUP_Debug, "Group Added")
        //Then here you clear Group[2]
        call GroupClear( udg_GROUP_Duel[2] )
        call DisplayTextToForce(udg_GROUP_Debug, "Group Cleared")
        call DisplayTextToForce(udg_GROUP_Debug, "Else Checking: [1]:" + I2S(CountUnitsInGroup(udg_GROUP_Duel[1])) + "[2]: " + I2S(CountUnitsInGroup(udg_GROUP_Duel[2])))
       // call TriggerExecute( gg_trg_Spawn_Duelists )

BTW, I'm not with my WE so I'm not sure if my syntax is right...

@Bribe: Double Post
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Okie dokie.

change those to what I give you here and also check my original post as it's been changed. You shouldn't be working with units, you should be working with unit type. Create a unit-type variable (array) called Duelist.

JASS:
set udg_Duelist[0] = 'h00A'
set udg_Duelist[1] = 'h00B'
set udg_Duelist[2] = 'h00C'
set udg_Duelist[3] = 'h00D'
 
Level 6
Joined
Jun 20, 2005
Messages
108
with your trigger, won't I have two of the same unit fighting? That's why I used groups.

Also, the kind of help I was expecting was someone to explain me why my code doesn't work. I wanna learn from my mistakes so I don't repeat them. Even if your code works, I'm more interested in learning why mine doesn't.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Will never create the same two units:

JASS:
constant function Telepath takes nothing returns string
    return "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl"
endfunction
 
function NewDuelist takes rect r, unit u, integer i returns unit
    if i == 0 then
        set i = udg_Duelist[GetRandomInt(0,3)]
        set bj_randDistCount = i
    else
        loop
            set i = udg_Duelist[GetRandomInt(0,3)]
            exitwhen i != bj_randDistCount
        endloop
    endif
    set u=CreateUnit(Player(15),i,GetRectCenterX(r),GetRectCenterY(r),0)
    call DestroyEffect(AddSpecialEffectTarget( Telepath() , u , "origin" )) 
    call SetUnitAnimation( u , "stand victory" )
    return u
endfunction
 
function Trig_Spawn_Duelists_Actions takes nothing returns nothing
    local unit u1=NewDuelist( gg_rct_Duel_Arena_1 , bj_lastCreatedUnit , 0 )
    local unit u2=NewDuelist( gg_rct_Duel_Arena_2 , bj_lastCreatedUnit , bj_randDistCount )
    call TriggerSleepAction(3)
    call IssueTargetOrder( u1 , "attack" , u2 )
    call IssueTargetOrder( u2 , "attack" , u1 )
    set u1=null
    set u2=null
endfunction

I know what you mean about figuring it out yourself.

What I saw with your unit groups was that you were switching group[2] into group[1] at the end of every cycle, so group[2] was emptied at the end. Also, the hidden units you use in the beginning that you add to group[1] are interfered with all the other units you're adding to group[1]

You were spawning a type equal to that of a random pick from group[1], and with the units you were adding to group[1] and never removing, that meant two of the same type existed in group[1], which is why I didn't care to originally include a filter to make sure only one of each ever spawned.

But the way I use type variable arrays is irrefutably more efficient and foolproof.
 
Last edited:
Status
Not open for further replies.
Top