• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Differences Between DestroyGroup and ClearGroup

Status
Not open for further replies.
I think clearing group is that you remove units and than you can add new units/or something to it.

Destroying it, destroys it and you must create a new group again if you want to do with the group something again.

thanks :) i have problem with "FirstofGroup", it always return same unit everytime, i want to get a random unit from a unit group, do you have a solution :confused:
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
There's a BJ function:

function GroupPickRandomUnit takes group whichGroup returns unit

But you could just as easily simulate a random unit by doing the following:

JASS:
function sth takes group g returns nothing
    local integer rnd = GetRandomInt(1, CountUnitsInGroup(g)
    local unit u
    loop
        set u = FirstOfGroup(g)
        exitwhen rnd == 1
        call GroupRemoveUnit(g, u)
        set rnd = rnd - 1
    endloop
    call KillUnit(u) // u is now a random unit from the group.
endfunction
 
There's a BJ function:

function GroupPickRandomUnit takes group whichGroup returns unit

But you could just as easily simulate a random unit by doing the following:

JASS:
function sth takes group g returns nothing
    local integer rnd = GetRandomInt(1, CountUnitsInGroup(g)
    local unit u
    loop
        set u = FirstOfGroup(g)
        exitwhen rnd == 1
        call GroupRemoveUnit(g, u)
        set rnd = rnd - 1
    endloop
    call KillUnit(u) // u is now a random unit from the group.
endfunction

erm i avoid using the BJs thing :)
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
First of all, it isn't a BJ. And second thing - I think you didn't get WHY you normally wouldn't want to use a BJ function. It's not because we are racists towards the letters B and J. It's because most of them are useless. If a function isn't useless, it doesn't freaking matter if there is a BJ stuck in it's name (and like I mentioned this isn't even a BJ function).
 
Level 7
Joined
Jul 20, 2008
Messages
377
thanks :) i have problem with "FirstofGroup", it always return same unit everytime, i want to get a random unit from a unit group, do you have a solution :confused:

When iterating through a group using FirstOfGroup, you would do this:

JASS:
function foo takes nothing returns nothing
	local group temp=CreateGroup()
	local unit nextUnit
	call GroupAddGroup(groupYouWantToIterateThrough, temp)
	loop
		set nextUnit=FirstOfGroup(temp)
		exitwhen nextUnit==null
		// Do your actions for each unit here....
		call GroupRemoveUnit(temp, nextUnit)
	endloop
	call DestroyGroup(temp)
	set nextUnit=null
	set temp=null
endfunction

That's the inline way to, anyway, without using Enum functions.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
I might be a little off-topic:
But why doesnt my WE take: call ClearGroup(udg_Variable) ?
I made a line of custom script and put that in it (with other variable name) And it keeps saying: 'function name expected'
 
Status
Not open for further replies.
Top