• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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