• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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:
Level 31
Joined
Jul 10, 2007
Messages
6,306
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