• 🏆 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!

[Solved] Issue with statics and struct children

Status
Not open for further replies.
Aim:
Have two different children structs that have their own static objects.

What happens:
When trying to set the children statics it will overwrite for all other parent children.

The code above prints "Test: 2 :: 2". I was looking for a way to make this "Test 1 :: 2"

vJASS:
library Test initializer init

    struct object
    endstruct

    struct parent
        public static object test = 0
    endstruct
 
    struct childOne extends parent
        private static method onInit takes nothing returns nothing
            set thistype.test = object.create()
        endmethod
    endstruct
 
    struct childTwo extends parent
        private static method onInit takes nothing returns nothing
            set thistype.test = object.create()
        endmethod
    endstruct
 
    private function init takes nothing returns nothing
        call BJDebugMsg("Test: " + I2S(childOne.test) + " :: " + I2S(childTwo.test))
    endfunction
 
endlibrary

Edit: I found a workaround by making the parent a module and including that module into the children structs.
 
Last edited:
Status
Not open for further replies.
Top