• It's time to dig through Hive's model database and dust off some oldie but goldie models and enter Hive's Texturing Contest #31 : Repurposing! Click here to enter!
  • 🏆 Hive's 5th HD Modeling Contest: Creep Camp is now open! Click here to enter!

Struct extends Array - Help

Level 3
Dec 16, 2010
Can someone explain how I can get unique id's for structs that follow the struct extends array type without any units or allocate() involved?

for instance I would like to have:

struct TEST extends array
    static method createNormal takes nothing returns thistype
         local thistype this = thistype[someID]
         return this

I would like to know techniques that people have used to generate "someID" as in the example above. And also I would like to know how they managed these structs and their indecies. Like how did you recycle them?

Edit: you know, Bribe seems to have done what I was trying to do. I suppose the unique index stuff from units was clouding my thought process.
Last edited:
Level 31
Jul 10, 2007
Here you are

Full commented look into the background workings of structs

//a struct that extends an array is code with the syntactic sugar of a struct
//this means that no extra code is generated

//structs normally generated create, destroy, and onDestroy
struct Hello extends array
    //instantiation can be a tricky thing. When a struct is created, you have to ensure
    //that the instance returned is unique. Furthermore, when a struct is destroyed,
    //you need to reuse that struct's instance to save on memory

    //instanceCount is a counter that continues to increase as new instances are created
    private static integer instanceCount = 0 //how many Hello's that are created

    //recycleCount is a counter that continues to increase as structs are destroyed
    //this is to ensure that destroyed instances are used the next time the struct
    //is created
    private static integer recycleCount = 0 //how many Hello ids that were recycled

    //recycle is an array that stored the destroyed instances
    private static integer array recycle //an array storing recycled Hello's

    //this is the create method, a method that creates unique instances of the struct
    //thistype is a keyword that translates into the struct's name
    //in this case, thistype would be Hello
    //if the struct was named BooYa, thistype would be BooYa
    public static method create takes nothing returns thistype
        //this is a keyword that refers to the current instance
        //static methods are like regular functions, so they don't get a this, which is
        //why I was able to declare one
        //static methods are called via struct.method()
        local thistype this

        //first check for any destroyed structs
        if (recycleCount > 0) then //if there are Hello's waiting to be reused
            //decrease the counter so that you are on the right slot in the array
            set recycleCount = recycleCount - 1 //dec counter

            //set the current instance to the destroyed struct
            set this = recycle[recycleCount] //use it
            //if there are no destroyed structs, make a new one by increasing
            //the instance counter
            set instanceCount = instanceCount + 1 //0 is null, so first inc by 1

            //set the current instance to the instance counter
            set this = instanceCount

        //perform creation code here :O

        //return the created struct
        return this

    //destroy is called when the struct is to be destroyed
    //this is not a static method
    //a non static method translates to this (using destroy as an example)
    //public static method destroy takes thistype this returns nothing
    //the instance of the struct is automatically passed in
    //they are called via structInstance.method()

    public method destroy takes nothing returns nothing
        //remember this is passed in, so it exists!
        //store this into the recycle variable
        //the first struct destroyed would be recycle[0] = this
        set recycle[recycleCount] = this
        //increase recycle counter
        set recycleCount = recycleCount + 1

        //if create was called, recycleCount would be decreased back down to 0
        //and recycle[0] would be used

        //put destruction code here

Above allows this
local Hello h = Hello.create()
call h.destroy()

If you have any sort of list, then you can use this model instead
struct Hello extends array
    private static thistype recycle = 0
    private static integer instanceCount = 0

    private thistype next
    //private thistype previous??

    static method create takes nothing returns thistype
        local thistype this

        if (recycle == 0) then
            set instanceCount = instanceCount + 1
            set this = instanceCount
            set this = recycle
            set recycle = recycle.next

        return this

    method destroy takes nothing returns nothing
        /*remove from list??
            set next.previous = previous.next
            set previous.next = next.previous

        set next = recycle
        set recycle = this

Really, the second model is faster in all scenarios, but most people use the first ; O.