• 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.

[Solved] Question about extending structs

Status
Not open for further replies.
Level 10
Joined
Jun 6, 2007
Messages
392
I'd like to extend Nestharus' Dummy struct so that in the constructor I add a special effect on the unit. Here's what I've tried:

JASS:
struct Element extends array
    
        thistype nextUnit
        thistype prevUnit
        private effect art
        private delegate Dummy Dummy
        
        static method create takes real x, real y, real facing returns thistype
            local thistype this = Dummy.create(x, y, facing)
            set this.art = AddSpecialEffectTarget(EFFECT, this.unit, "origin")
            set Dummy = this
            return this    
        endmethod
        
        method destroy takes nothing returns nothing
            call DestroyEffect(this.art)
            call Dummy.destroy()
        endmethod
    
    endstruct

The special effect isn't visible, so I believe that I'm not referencing the unit correctly. What is the correct syntax?
 
Last edited by a moderator:
JASS:
struct Element extends array
        private effect art
        
        //call this.Dummy to access Dummy, only use static delegates, arrays are silly
        method operator Dummy takes nothing returns Dummy
            return this
        endmethod
        
        static method create takes real x, real y, real facing returns thistype
            local thistype this = Dummy.create(x, y, facing)
            //you were using this.unit, relying on the delegate, but you set the delegate
            //afterwards, so the delegate was 0, so it was 0.unit, which was null
            set art = AddSpecialEffectTarget(EFFECT, Dummy.unit, "origin")
            /*
            set this.art = AddSpecialEffectTarget(EFFECT, this.unit, "origin") //used delegate here, but didn't set yet
            set Dummy = this //see how it's set after you were already using it above?
            */
            return this    
        endmethod
        
        method destroy takes nothing returns nothing
            call DestroyEffect(art)
            call Dummy.destroy()
        endmethod
    
    endstruct
 
Status
Not open for further replies.
Top