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.

[Solved] How to Group unit without uses boolenexplr

Discussion in 'Triggers & Scripts' started by ALTELMA, Apr 20, 2012.

  1. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Example for me plz
     
  2. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Use FirstOfGroup.

    <<< EDIT >>>
    here is an example
    Code (vJASS):

    globals
        group g = CreateGroup()
    endglobals

    // ===========================================================

    function MatchingUnit takes unit u returns boolean
        return u == UNIT_TYPE_HERO // this is just an example you will have to set your own filter
    endfunction

    function example takes real x, real y, real radius returns nothing
        local unit u
        call GroupEnumUnitsInRange(g,x,y,radius,null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            if MatchingUnit(u) then @/*EDIT:you could also apply the filter here and no need for another function call*/@
                // Do stuff here
            endif
            call GroupRemoveUnit(g,u)
        endloop
    endfunction
     
     
    Last edited: Apr 20, 2012
  3. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    OK Thanks you a lot. I'll try it.
     
  4. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    No problem, if you have any question just ask.
     
  5. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    OK thanks you, I have question about Event Every times X second. Can I use other function instead. Because I use this event for many trigger. I worry its slow my map and causes many leak. How can I fix that problem?

    Sorry for my language.
     
  6. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    if the loop is instant,
    bj_lastCreatedGroup
    is fine than creating a group...

    about X seconds, you could use timers instead then pause the timer if you dont use the function...
     
  7. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    I know about
    bj_lastCreatedGroup
    but I assumed the loop is not instant when I wrote this example.
     
  8. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    I have a question. If I use many if/else (About 20 - 30) on one function. It's cause my map is slow down.
     
  9. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    Mmmm depends. There are ways to avoid having to create long if/else chains, but it's "doable" if isn't a very used action.
     
  10. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Should I use many trigger instead? It's best way to create recipe item. If It's true,I will came back to use old trigger item.
     
  11. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    No. There are systems here in hive for recipe Items. The way it works is with loops and pre-saved data. It's something like having a list of 100 values, and you tell the system "Find value 5 in the list of 100 values"... sort of.
     
  12. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    I ever seen it, but It's loop over 100 time to find any target item, but Why do I think that don't work?
    That system you mention is Recipe Systems
     
  13. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Optimization is great and all, but sometimes just write clean code...

    Also he'd presumably not be using a global at all if it were anything but instant.

    (Oh, and to the OP, the method a few posts up is really bad [not that I can blame him, he gave you what you asked for]... just use a boolexpr, there's really no reason not to)
     
  14. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Thanks All guys, Now I understand about topic "how to create group without boolexpr".
     
  15. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    I disagree, there are reasons to avoid it.
    First, it's much faster because each time the boolexpr is evaluated a new thread is created, while it's not with a null filter, but yeah 99 % of times it doesn't matter at all.

    It doesn't split the code, then you can use your locals without temp globals.
    I agree that the loop is verbose, but still less than writing a boolexpr, and with Cohadar's jasshelper this loop is just like that :

    for <unit> in <group>
    // filter and do stuff with <unit>
    endfor
     
  16. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
  17. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Troll-Brain example for me plz.
     
  18. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    I think that, what Troll-Brain means is that the "Matching" part isn't really needed outside the GroupEnum to work with the units. You can filter the units inside the group as someone said before in this same thread.

    Code (vJASS):

        call GroupEnumUnitsInRange(g,x,y,radius,null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            if (First comparison) and (Second comparison) and (Third comparison), etc. then
                // Do stuff here
            endif
            call GroupRemoveUnit(g,u)
        endloop
    endfunction
     
     
  19. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    OK thanks a lot
     
  20. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Err I wonder Value X and Y on function GroupEnumUnitsInRange Tell me more about agrument of that function.

    Code (vJASS):

    function Trig_CountUnitGroup_Actions takes nothing returns nothing
       
        local unit u
        local group g =CreateGroup()
        local integer unitCount
       
        call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)
       
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
                if(GetUnitTypeId(u) == 'hf00')then
                    set unitCount =unitCount + 1
                    call BJDebugMsg(I2S(unitCount))
                endif
                call GroupRemoveUnit(g,u)
        endloop
    endfunction

    //===========================================================================
    function InitTrig_CountUnitGroup takes nothing returns nothing
        set gg_trg_CountUnitGroup = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
        call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
    endfunction