Unit grouping problem in Jass

Kayoss666

Member
Reaction score
7
i had this working in gui but i am trying to learn more about jass so i copied then converted but after trying to change all the commands to natives it doesn't work.
the gui version
Trigger:
  • StoreCreeps
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Custom script: call DestroyGroup(udg_Creep_Group)
      • Set Creep_Group = (Units owned by Neutral Hostile)
      • Unit Group - Pick every unit in Creep_Group and do (Actions)
        • Loop - Actions
          • Set Creep_Count = (Creep_Count + 1)
          • Set Creep_Start_Position[Creep_Count] = (Position of (Picked unit))
          • Unit - Set the custom value of (Picked unit) to Creep_Count


the code in native jass
JASS:
library True initializer Init
 
globals
boolexpr TrueCnd
endglobals
 
private function True takes nothing returns boolean
return true
endfunction
 
private function Init takes nothing returns nothing
set TrueCnd = Condition(function True)
endfunction
 
endlibrary
 
function Trig_StoreCreeps_Copy_2_Func002A takes nothing returns nothing
call GroupAddUnit( udg_Creep_Group, GetEnumUnit() )
set udg_Creep_Count = ( udg_Creep_Count + 1 )
set udg_Creep_Start_Position[udg_Creep_Count] = GetUnitLoc(GetEnumUnit())
call SetUnitUserData( GetEnumUnit(), udg_Creep_Count )
endfunction
 
function Trig_StoreCreeps_Copy_2_Actions takes nothing returns nothing
call DestroyGroup(udg_Creep_Group)
//***
call GroupEnumUnitsOfPlayer(udg_Creep_Group, Player(PLAYER_NEUTRAL_AGGRESSIVE), TrueCnd)
call ForGroup( udg_Creep_Group, function Trig_StoreCreeps_Copy_2_Func002A )
//*** i believe that my problem is here. before trying to make it native commands it was
//set udg_Creep_Group = GetUnitsOfPlayerAll(Player(PLAYER_NEUTRAL_AGGRESSIVE))
//call ForGroupBJ( udg_Creep_Group, function Trig_StoreCreeps_Copy_Copy_Func003A )
endfunction
 
//===========================================================================
function InitTrig_StoreCreeps_Copy_2 takes nothing returns nothing
set gg_trg_StoreCreeps_Copy_2 = CreateTrigger( )
call TriggerRegisterTimerEvent( gg_trg_StoreCreeps_Copy_2, 0.10, false )
call TriggerAddAction( gg_trg_StoreCreeps_Copy_2, function Trig_StoreCreeps_Copy_2_Actions )
endfunction
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
In your "Actions" function, you destroy the group before enumerating the units. You either have to set it to "CreateGroup()" again, or just don't destroy it before enumerating.

Basically, when you use GroupEnumUnits(), it enumerates the units and then runs through the filter. If the filter is true for that unit (it checks for each unit), then the units are added to the group. Otherwise it is left empty.

Using groups in JASS is a bit different than using them in GUI, though. You can get some more information here:
http://www.hiveworkshop.com/forums/2411951-post10.html

Note that some of the sample scripts at the bottom of that post use vJASS, which is an extension that makes any JASS coder's life much easier. It is bundled with Jass NewGen Pack.

That post should demonstrate the different methods in using groups. If you need any more info, feel free to ask.

P.S. The boolexpr "True" dummy condition thing doesn't apply any more. You can just input null if you aren't using a filter.
 

Kayoss666

Member
Reaction score
7
Thank you for the info and site link. I actually totally changed my code sense posting this and now have it working but this info should be useful later on. and i am using Jass New Gen and thank for the boolexpr fact i didn't know that null no longer leaked
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top