HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Copying a Unit Group variable

04-10-2003, 07:07 PM#1
KaTTaNa
I have 2 local variables: (group is a unit group)
local group mygroup1
local group mygroup2

I want mygroup2 to be a copy of mygroup1
set mygroup2 = mygroup1

Above is the most obvious yet useless solution.
This is why:
set mygroup2 = mygroup1
RemoveUnitFromGroup(myUnit, mygroup2)

Now myUnit has ALSO been removed from the mygroup1.
It assigns it as a pointer instead of a clone! How do I copy mygroup1 into mygroup2?emote_sweat emote_sweat
04-10-2003, 07:32 PM#2
ChoboMapper
you need to pick every unit in unitgroup1 and add them to unitgroup 2... like

function Trig_part2 takes nothing returns nothing
call GroupAddUnitSimple( GetEnumUnit(), unitgroup2) )
endfunction

function Trig_part1_Actions takes nothing returns nothing
call ForGroup( unitgroup 1, function Trig_part2 )
endfunction
im sure theres a better way to do this but i just got into jass
04-10-2003, 11:03 PM#3
Nozdormu
He's right, you need a deep copy. I'm not sure what all is in the group, but you'll need to break it down and copy element by element.
04-11-2003, 12:51 AM#4
FyreDaug
A unit group has multiple units (apparently, otherwise it wouldn't be a group ;)) So think of it as an arrayed variable, each unit is it's own seperate index. Think of the whole variable as a folder, and all the units as individual files. You can't just copy the folder, you need to copy all the files. I donno if that's a good enough reference, but I hope you get the point.
04-11-2003, 04:22 AM#5
KaTTaNa
CoboMapper>>
I'm doing this inside a pick all units thing so that wouldn't work.
Besides, my local variables will not be accible from Trig_Part2. I could make them global, yes, but I already have too many and I'm trying to narrow it down.

FyreDaug>>
I know what a unit group is and what units are. It doesn't contain units. It contains pointers to unit. I understand what you mean but I knew that already (no offense) and I'm looking for a way around it.
To keep it to your filesystem examples I'll explain what the problem is. When I assign the variable to my first one, it does not copy the folder - it makes a shortcut to it. So when I go into my new variable (the shortcut) and change the files, the files that I actually change are the original ones so both variables get altered.

In Java there is a function called Clone.
Is there anything similiar to that in Jass?
04-15-2003, 07:34 AM#6
Guest
Then make a third group and then:

then do the remove thing and add the unit to both group 2 and group 3 then you have two clones of group 1