Attaching Struct In a Callback?

MasterRofl

New Member
Reaction score
8
How do I make it so that I can use the struct in the callback function?
JASS:
library NetTrap initializer Init uses ABC

private struct Net
    unit DyingUnit
    group TrapGroup
    location TrapLocation
        method onDestroy takes nothing returns nothing
            set.TrapGroup = null
            set.TrapLocation = null
        endmethod
endstruct

private function Callback takes nothing returns nothing
    local unit NetDummy = CreateUnitAtLoc( GetOwningPlayer(n.DyingUnit), GetUnitLoc(GetEnumUnit()), 0 )
    call UnitAddAbility( NetDummy, 'A01V' )
    call SetUnitAbilityLevel( NetDummy, 'A01V', GetUnitAbilityLevel( udg_JL_Caster, 'A03O' ))
    call IssueTargetOrderById( NetDummy, 'A01V', GetEnumUnit())
    call RemoveUnit( NetDummy )
endfunction

private function Actions takes nothing returns nothing
    local Net n = Net.create()
    set n.TrapLocation = GetUnitLoc(GetDyingUnit())
    set n.TrapGroup = GetUnitsInRangeOfLocMatching( 200., n.TrapLocation, null )
    set n.DyingUnit = GetDyingUnit()
    call ForGroup( n.TrapGroup, function Callback )
    call n.destroy()
endfunction

private function Conds takes nothing returns boolean
    return GetDyingUnit() == 'n00T'
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_UNIT_DEATH)
    call TriggerAddCondition(t, Condition( function Conds ))
    call TriggerAddAction(t, function Actions)
    set t = null
endfunction

endlibrary
 

MasterRofl

New Member
Reaction score
8
Well, what I have there is a callback for "ForGroup," and there's no timer in that right? Do I use SetTriggerStruct?
 

Artificial

Without Intelligence
Reaction score
326
I can't think of any attachment system that could retrieve the struct in a ForGroup callback. Probably mainly because there isn't much to attach to.
You could set the struct to a global variable or loop through the group using the FirstOfGroup thingy.
 

Flare

Stops copies me!
Reaction score
662
Easiest way is probably to do global struct i.e.
JASS:
private struct Net
...
endstruct

globals
  private Net gdata
endglobals

function TimerCallback takes nothing returns nothing
  local Net data = GetTimerStructA (GetExpiredTimer ())
... //other local declarations and sh*t like that
  set gdata = data
  call GroupEnum... (whichGroup, ...)
  call ForGroup (whichGroup, whichCallback)


And then use gdata.structmember in whichCallback
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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