[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