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

[vJASS] arrays inside structs

Status
Not open for further replies.
Level 8
Joined
Feb 3, 2013
Messages
277
Sorry, maybe the answer is simple, but I'm have a bit of an issue trying to understand how I would go about this.

JASS:
private struct Hooks 
    unit array chain[100]
    unit head 
endstruct

How would I write this, when I'm using the struct extends array method?

edit: -_- I finally understood it again, I'm sorry

for anyone whos wondering, basically for something like above you would have to do this
JASS:
private struct Hooks extends array
    integer count
    
    static unit array chain
    unit head
    
    
    private static integer array ccount      // No such thing as magic, the arrays in structs are dealt with in math and have a limit as well
    private static integer array rn
    private static integer ic = 0
    
    static method Create takes nothing returns nothing
        local integer this = rn[0]
        
        if this == 0 then
            set ic = ic + 1
            set this = ic
        else
            set rn[0] = rn[0]
        endif
        
        if this > 80 then                    // Basically the instance can't go beyond 8191, so one integer below 8191/your array max cap
            set this == 0 then               // Or you can return here
        endif
        
        set .ccount = (this-1) * 100         // The number you multiply by would be your array max cap
    endmethod
endstruct


    chain[.ccount + .count]                  // To refer/index the unit chain, it would be something like this
                                             // BTW, this is exactly how the allocation method in vJASS compiler does it
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
just use Table by Bribe, you will have around 2^32 storage space for each instance of your struct

this

JASS:
struct MyStruct
    Table hooks
    integer unit

    public static method create takes nothing returns thistype
        //....
        set hooks = Table.create()
        //...
    endmethod
endstruct

set myStructInstance.hooks[myNumber between 0 and 2^31-1] = myValue
 
Status
Not open for further replies.
Top