HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Passing struct "structures"

08-18-2008, 04:08 AM#1
fX_
how do i pass a particular, created struct and its methods over to another struct w/c i will use to execute the methods of the former?

Example:

i create from struct: SPELL A an instance A in an ability trigger then pass it over to another struct: EFFECT, w/c will execute A's functions/methods. in the struct: EFFECT, how do i identify the struct to be run (A) its "struct-type" (SPELL A) and its associated methods (those in struct SPELL A); how do i execute SPELL A's methods for instance A in struct EFFECT?
08-18-2008, 04:22 AM#2
Vexorian
Please explain what you want to do. Cause that example you just posted is very confusing.
08-18-2008, 04:37 AM#3
fX_
Collapse JASS:
library Effect
globals
    integer array gEFFECTDATA
    integer gINT_CountEffectData
endglobals

struct EffectData
    ||(ARBITRARY STRUCT-TYPE (that is, SPELL A/ SPELL B)|| myStruct
    
    static method Create takes integer abilityStruct returns EffectData
        local EffectData NewData = EffectData.allocate()
        set NewData.myStruct = abilityStruct
        call NewData.Execute()
        return NewData
    endmethod
    
    method Execute takes nothing returns nothing
        call myStruct.Execute()
        call BJDebugMsg("GO")
    endmethod
endstruct

endlibrary


Collapse JASS:
function Trig_Spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'Awrs'
endfunction

struct SpellA
    integer intEffectDataIndex
    unit uTarget
    unit uCaster
    timer timT
    
    static method Create takes unit target, unit caster, integer levelAbilityCast returns SpellA
        local Spell NewData = Spell.allocate()
        set gINT_CountEffectData = gINT_CountEffectData + 1
        set NewData.intEffectDataIndex = gINT_CountEffectData
        set NewData.uTarget = target
        set NewData.uCaster = caster
        set NewData.timT = CreateTimer()
        return NewData
    endmethod
    
    method Execute takes nothing returns nothing
        call BJDebugMsg("YAY")
//        if GetUnitState(this.uCaster, UNIT_STATE_MANA) < 300 then
  //      call this.Destroy()
    //    endif
    endmethod
    
    method Destroy takes nothing returns nothing
    call BJDebugMsg("GONE")
    endmethod
endstruct

function Trig_Spell_Actions takes nothing returns nothing
    
    call EffectData.Create(Spell.Create(GetSpellTargetUnit(), GetTriggerUnit(), GetUnitAbilityLevel(GetTriggerUnit(), 'Awrs')))
endfunction

//===========================================================================
function InitTrig_SpellA takes nothing returns nothing
    set gg_trg_SpellA = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SpellA, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition( gg_trg_SpellA, Condition(function Trig_Spell_Conditions))
    call TriggerAddAction( gg_trg_SpellA, function Trig_Spell_Actions )
endfunction


Collapse JASS:
function Trig_SpellB_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'FLAMESTRIKE WOW'
endfunction

struct SpellB
    integer intEffectDataIndex
    unit uTarget
    unit uCaster
    timer timT
    
    static method Create takes unit target, unit caster, integer levelAbilityCast returns SpellB
        local Spell NewData = Spell.allocate()
        set gINT_CountEffectData = gINT_CountEffectData + 1
        set NewData.intEffectDataIndex = gINT_CountEffectData
        set NewData.uTarget = target
        set NewData.uCaster = caster
        set NewData.timT = CreateTimer()
        return NewData
    endmethod
    
    method Execute takes nothing returns nothing
        call BJDebugMsg("YAY")
//        if GetUnitState(this.uCaster, UNIT_STATE_MANA) < 300 then
  //      call this.Destroy()
    //    endif
    endmethod
    
    method Destroy takes nothing returns nothing
    call BJDebugMsg("GONE")
    endmethod
endstruct

function Trig_SpellB_Actions takes nothing returns nothing
    
    call EffectData.Create(Spell.Create(GetSpellTargetUnit(), GetTriggerUnit(), GetUnitAbilityLevel(GetTriggerUnit(), 'Awrs')))
endfunction

//===========================================================================
function InitTrig_SpellB takes nothing returns nothing
    set gg_trg_SpellB = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SpellB, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition( gg_trg_SpellB, Condition(function Trig_SpellB_Conditions))
    call TriggerAddAction( gg_trg_SpellB, function Trig_SpellB_Actions )
endfunction
08-18-2008, 04:46 AM#4
fX_
i want to treat the ability struct as an object, operated on by the EFFECT struct; this, so i can "open it up" - change values, terminate it, etc.

i want to be able "pause", transfer(spell steal), "resist", block, etc. spell effects.

i do not know how to have my operator, EFFECT, open the structs up and manipulate them at its table (library Effect).
08-18-2008, 06:34 AM#5
the-thingy
From my understanding of what you're saying (you want to be able to use struct B's methods for struct A instances?), couldn't you make struct B a parent of A i.e.
(not sure on whether you can use struct B's members, or static methods)

Collapse JASS:
struct B
...
endstruct

struct A extends B
...
endstruct
08-18-2008, 01:51 PM#6
Vexorian
fX_: I am quite sure interfaces are the solution to this issue, if after reading the interfaces part of the manual and the sample that comes in jasshelper/samples you cannot understand it, I would have to post code, but in order to post code that does what you want to do, you will have to describe what you truly intend to do, to do this, explain the behaviors of all your functions, but avoid trying to use words like struct or structure to explain that stuff, think that you are designing the system a lot before thinking about the implementation.