1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Unit Group being cleared after the trigger!

Discussion in 'World Editor Help Zone' started by mecatronic, Mar 21, 2010.

  1. mecatronic

    mecatronic

    Joined:
    Jun 20, 2005
    Messages:
    112
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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):

    Code (vJASS):
    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
     
  2. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,053
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Does this make it easier?:

    simplified
    Code (vJASS):

    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: Mar 22, 2010
  3. mecatronic

    mecatronic

    Joined:
    Jun 20, 2005
    Messages:
    112
    Resources:
    1
    Maps:
    1
    Resources:
    1
    The spawning trigger is included in my Unit Preloading trigger, here it is:

    Code (vJASS):
        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.
     
  4. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    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....

    Code (vJASS):

     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
     
  5. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,053
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    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.

    Code (vJASS):

    set udg_Duelist[0] = 'h00A'
    set udg_Duelist[1] = 'h00B'
    set udg_Duelist[2] = 'h00C'
    set udg_Duelist[3] = 'h00D'
     
     
  6. mecatronic

    mecatronic

    Joined:
    Jun 20, 2005
    Messages:
    112
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I was originally working with unit types, but eventually I found it was easier to work with units because I was using groups, and there's no such thing as unit type groups.
     
  7. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,053
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    The unit groups you were using will bug and glitch. The two things I gave you will work exactly the way you want. Mine does everything yours does except it uses unit types. Try it out.
     
  8. mecatronic

    mecatronic

    Joined:
    Jun 20, 2005
    Messages:
    112
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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.
     
  9. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,053
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Will never create the same two units:

    reveal
    Code (vJASS):

    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: Mar 26, 2010