• 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) Refer to the group a unit is picked from

Status
Not open for further replies.
Level 3
Joined
Sep 11, 2008
Messages
58
I have the following method which contains a ForGroup call for the group 'enemies'...

JASS:
public method execute takes nothing returns nothing
        local group enemies = CreateGroup()
        call GroupEnumUnitsInRange(enemies, GetUnitX(this.ofTarget), GetUnitY(this.ofTarget), this.range, Condition(function s_task_eval_situation.cb_is_enemy))
        call SetStructA(enemies, this)
        call ForGroup(enemies, function s_task_eval_situation.cb_add_to_enemiesInRange)
        call GetStructA(enemies, true)
        call this.ts.execute_next()
endmethod

...in the callback function i would like to refer to the group 'enemies' (i marked it within the following method with [HERE])...

JASS:
static method cb_add_to_enemiesInRange takes nothing returns nothing
        local unit pickedUnit = GetEnumUnit()
        local s_task_eval_situation t = GetStructA([HERE], false)
        set t.enemiesInRange[t.eirIdx] = pickedUnit
        set t.eirIdx = t.eirIdx + 1
endmethod

Is there a way to refer to that group 'enemies'?

Thanks for any answers!
whisp
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Pass the group through a global variable (I see you're not using any wait actions so there's no problem in doing so), or use:

JASS:
local group g = ...
local unit u
loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    call GroupRemoveUnit(g, u)
    Do stuff with u
endloop
// The group is empty after this function, so if you need to use it afterwards, make a copy of it.

If you go for the global variable, then you might as well just pass the struct through a variable rather than the group.
 
Level 3
Joined
Sep 11, 2008
Messages
58
Thanks for your answer. The problem is, that this callback most likely will be executed multiple times parallely (at least i assume it, i don't know a lot about the WC3 threading mechanisms). Thus i assume using a global variable could lead to wrong results...

But your Jass-Code works perfectly for my needs. Thanks!
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Thanks for your answer. The problem is, that this callback most likely will be executed multiple times parallely (at least i assume it, i don't know a lot about the WC3 threading mechanisms). Thus i assume using a global variable could lead to wrong results...

But your Jass-Code works perfectly for my needs. Thanks!

As I said, there won't be any problems if you don't use wait actions or timers. Jass is single threaded.
 
Status
Not open for further replies.
Top