Snippet GetUnitofGroup

Compute(<>)

New Member
Reaction score
1
Hi there this is my first snippet
Hope you like it

Requires
JNGP

Info: This snippet returns a unit for the group so its like FirstOfGroup() but can return and unit. So if you want the ThirdOfGroup you would do this
GetUnitofGroup(3,whichGroup, fasle) easy.
JASS:
library Group

    globals
        private unit array u
        private unit array u2
        private group g = CreateGroup()
    endglobals

    function GetUnitofGroup takes integer i, group grp, boolean Remove returns unit
        local integer h = i
        if i != 1 then
            loop
                exitwhen h == 0
                set h = h - 1
                set u[h] = FirstOfGroup(grp)
                call GroupRemoveUnit( grp, u[h])
                call GroupAddUnit( g, u[h])
            endloop
            set h = i
            loop
                exitwhen h == 0
                set h = h - 1
                set u2[h] = FirstOfGroup(g)
                call GroupRemoveUnit( g, u2[h])
                call GroupAddUnit( grp, u2[h])
            endloop
            if Remove == true then
                call GroupRemoveUnit( grp, u[0])
            endif
            return u[0]
        else
        set u[0] = FirstOfGroup(grp)
        if Remove == true then
            call GroupRemoveUnit( grp, u[0])
        endif
        return u[0]
        endif
    endfunction

endlibrary


Please comment on what is bad and could be improved.
v1.00 - Released
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
I haven't found any uses for this

also erm... if I want to get ThirdOfGroup so I will lose "First" and "Second" unit in that group ?
 

Compute(<>)

New Member
Reaction score
1
no if you looked they get added back to the group. This could be used for random units from group, group loop with a loop.
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
But you can't really know what number resembles each unit anyway? I can't imagine any use for this.
 

Romek

Super Moderator
Reaction score
964
People often use FirstOfGroup because it simply returns a unit within the group, not because they want the first unit.
Most people don't even know (or care) about the order in which units are added into the group.
 

Compute(<>)

New Member
Reaction score
1
meh i though this could be a small part of something big for groups that could give people more flexability with groups
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
>no if you looked they get added back to the group. This could be used for random units from group, group loop with a loop.

oh sorry, my bad :p

>People often use FirstOfGroup because it simply returns a unit within the group, not because they want the first unit.
Most people don't even know (or care) about the order in which units are added into the group.


e.g: me :D
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
Compute, how about giving us an example where this could be useful? It seems just like THAT unnecessary :/
 

The Undaddy

Creating with the power of rage
Reaction score
55
Besides, even if anyone had any use at all for this, using your snippet changes the order of the units in order to get to a particular one,so even then it's completely useless.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
well this could be used for safe group looping. Meh anyway why the group and u2 they could be avoided.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
Well it would look like this
JASS:
library Group

    globals
        private unit array u
    endglobals

    function GetUnitofGroup takes integer i, group grp, boolean Remove returns unit
        local integer h = i
        if i != 1 then
            loop
                exitwhen h == 0
                set h = h - 1
                set u[h] = FirstOfGroup(grp)
                call GroupRemoveUnit( grp, u[h])
            endloop
            set h = i
            loop
                exitwhen h == 0
                set h = h - 1
                call GroupAddUnit( grp, u[h])
            endloop
            if Remove == true then
                call GroupRemoveUnit( grp, u[0])
            endif
            return u[0]
        else
            set u[0] = FirstOfGroup(grp)
            if Remove == true then
                call GroupRemoveUnit( grp, u[0])
            endif
            return u[0]
        endif
    endfunction
 

Compute(<>)

New Member
Reaction score
1
Oh i see but here is a funtion that uses the snippet

JASS:
library Group

    globals
        private unit array u
        unit GroupUnit
    endglobals

    function GetUnitofGroup takes integer i, group grp, boolean Remove returns unit
        local integer h = i
        if i != 1 then
            loop
                exitwhen h == 0
                set h = h - 1
                set u[h] = FirstOfGroup(grp)
                call GroupRemoveUnit( grp, u[h])
            endloop
            set h = i
            loop
                exitwhen h == 0
                set h = h - 1
                call GroupAddUnit( grp, u[h])
            endloop
            if Remove == true then
                call GroupRemoveUnit( grp, u[0])
            endif
            return u[0]
        else
            set u[0] = FirstOfGroup(grp)
            if Remove == true then
                call GroupRemoveUnit( grp, u[0])
            endif
            return u[0]
        endif
    endfunction
    
    function GroupLoop takes group grp, boolean empty, string s returns nothing
        local integer i = 0
        loop
            set i = i + 1
            set GroupUnit = GetUnitofGroup(i, grp, empty)
            exitwhen GroupUnit == null
            call ExecuteFunc(s)
        endloop
    endfunction

endlibrary
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Romek said:
Most people don't even know (or care) about the order in which units are added into the group
So there is a super dude somewhere on the world, which know how units are added in the group, i want to know him <3

EDIT : I can't call Chuck Norris, since our phones are not compatible with his one. :(
 

Compute(<>)

New Member
Reaction score
1
okay you people asked for a use and i gave one do i need to give more, it think the one i gave most people use.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
okay you people asked for a use and i gave one do i need to give more, it think the one i gave most people use.

Your function could easily be avoided by just using a ForGroup. You're looping through i units of the group, for every unit in the group. Not exactly a smart use for this.

Instead, you could do something like this:

JASS:


globals
    string func
    unit enum
endglobals

function ExecuteS takes nothing returns nothing
    set enum = GetEnumUnit()
    call ExecuteFunc(func)
endfunction

function GroupLoop takes group grp, boolean empty, string s returns nothing
    set func = s
    call ForGroup(grp,function ExecuteS)
    if empty then
        call GroupClear(grp)
    endif
endfunction
 

Jesus4Lyf

Good Idea™
Reaction score
397
FirstOfGroup is deprecated...

JASS:
library Group

    globals
        private unit array u
        private unit array u2
        private group g = CreateGroup()
    endglobals

    function GetUnitofGroup takes integer i, group grp, boolean Remove returns unit
        local integer h = i
        if i != 1 then
            loop
                exitwhen h == 0
                set h = h - 1
                set u[h] = FirstOfGroup(grp)
                call GroupRemoveUnit( grp, u[h])
                call GroupAddUnit( g, u[h])
            endloop
            set h = i
            loop
                exitwhen h == 0
                set h = h - 1
                set u2[h] = FirstOfGroup(g)
                call GroupRemoveUnit( g, u2[h])
                call GroupAddUnit( grp, u2[h])
            endloop
            if Remove == true then
                call GroupRemoveUnit( grp, u[0])
            endif
            return u[0]
        else
        set u[0] = FirstOfGroup(grp)
        if Remove == true then
            call GroupRemoveUnit( grp, u[0])
        endif
        return u[0]
        endif
    endfunction

endlibrary

-->
JASS:
library Group
    globals
        private unit Result
        private integer Count
    endglobals
    private function GetUnitEnum takes nothing returns nothing
        set Count=Count-1
        if Count==0 then
            set Result=GetEnumUnit()
        endif
    endfunction
    function GetUnitOfGroup takes group grp, integer i/*, boolean Remove*/ returns unit
        set Result=null
        set Count=i
        call ForGroup(grp,function GetUnitEnum)
        return Result
    endfunction
endlibrary

Still isn't useful, sadly.

Hey, welcome to TheHelper. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top