• 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] Transferring data in structs

Status
Not open for further replies.
Level 10
Joined
Sep 21, 2007
Messages
517
How can i transfer data from one struct to another? for example, a unit channels an ability, i save a timer in struct A, and in struct B extends struct A, i call dat.destroy(), but i want the timer from struct A to be destroyed? how can i get its reference? does it have to be CS, hashtables or whatnot or can this be done in structs too? (im pretty sure its can, im just bad at OOP and JASS)
 
Level 4
Joined
Apr 16, 2009
Messages
85
child structs have access to all (non private) variables and methods of its parent so if B is really a child of A theres no need to "transfer" anything as you just could do B.unit when unit is a variable of A

and btw when you call B.destroy() and B extends A both B.onDestroy() and A.onDestroy() get called (in that order)
 
Level 10
Joined
Sep 21, 2007
Messages
517
so lets say there is triggernig unit who stopped the channeling, how would we load the data based on the unit, do we have to do a loop to so what unit that unit is, or can we use any other method? like TriggeringUnits = GetTriggerUnit() for each loop and if/then ... you know the rest.
 
Level 4
Joined
Apr 16, 2009
Messages
85
oh you mean attachments well just use Vexorians Table for that
something like the following should work
JASS:
scope Bla initializer init
    globals
        private HandleTable UnitTable
    endglobals

    function Attach takes unit u, #struct# s returns nothing
        set UnitTable[u] = integer(s)
    endfunction

    function GetAttached takes unit u returns #struct#
        return #struct#(UnitTable[u])
    endfunction

    private function init takes nothing returns nothing
        set UnitTable = HandleTable.create()
    endfunction
endscope

o/c you would have to replace #struct# by your struct name
 
Status
Not open for further replies.
Top