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

Questions about struct array member

Status
Not open for further replies.
Level 22
Joined
Feb 6, 2014
Messages
2,466
Hello fellow modders/coders, I have a few question regarding struct array members because I don't have JNGP at the moment so I can't test it myself
1. If the struct extends an array, can I still assign array members?
If that is the case, does allocation work differently?
2. Example my struct has an integer array member Q[5]. What are the index after JassHelper compiles?
this.Q[1] -> Si_Struct_Q[this*5 + 1]??
this.Q[4] -> Si_Struct_Q[this*5 + 4]??
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
1. Array structs can only have static array members.
2. s___MyStruct_Q[s__MyStruct_Q[this]+4] on both Vexorians and Cohadars (basically what you said)

1. Meaning?
2. Hmm, what I said (wrote) and what you wrote are different. Mine has multiplication to support 2d arrays. If no multiplication is involved, then each instance is a multiple? example, 5, 10, 15, etc. so it will not conflict with other instances??

EDIT': If you notice, my questions are kinda related. So If answer to 1. is allocation work the same, it is safe to assume that my hypothesis in 2. is correct.
 
Last edited:
Level 19
Joined
Jul 14, 2011
Messages
875
1. Structs that extend array can only have static array members
JASS:
struct MyStruxt extends array
    integer array Q[5] // JassHelper complains
    static integer array Q1 // Fine
endstruct
You also have to implement the allocation by yourself.
2. Oh, yeah you're right. I should also note that in the generated constructor JassHelper adds set s__MyStruct_Q[this]=(this-1)*5, where 5 is the array size.
The size (if any) also determines how much instances of the struct can exist at the same time.
Edit: Size, as in, the biggest size of all of its array members.
Edit2: In case the 2nd question was about structs that extend array, you cannot do this.someArray[5] (because you cannot declare such member in the first place).
 
If you want arrays in your structs, use the default allocation and don't bother with extends array.

There is a reason why the default implementation of structs exists. And the reason is just that: better usability. extends array will break a lot of stuff (like correct struct inheritance) for little to no real gain (other than a minor speed difference).
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
If you want arrays in your structs, use the default allocation and don't bother with extends array.

There is a reason why the default implementation of structs exists. And the reason is just that: better usability. extends array will break a lot of stuff (like correct struct inheritance) for little to no real gain (other than a minor speed difference).

Yeah you're right.
 
Status
Not open for further replies.
Top