• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Just arrays

Status
Not open for further replies.
Level 7
Joined
Apr 5, 2011
Messages
245
JASS:
type my_array extends integer array
struct A
     my_array A_array
     method destroy takes nothing returns nothing
          call A_array.destroy()
     endfunction
endstruct
Is it needed?

Or I can do this:
JASS:
struct A
     integer array A_array
endstruct
And everything will be fine?
 
Note that you won't be able to use the dot syntax if you define it as an integer. Technically you can if you do A(int) or thistype(int) but that usually gets clunky. So if you want, you can just define it as:
JASS:
struct A
    thistype array A_array[50]
endstruct

The keyword thistype represents the type of the struct that the variable is in. So in the case above, it would be type A. While thistype was mostly intended for use in modules, it can be useful in other cases as well. I usually just use thistype to define variables of a struct type unless I need to refer to a different struct than the one it is already in.
 
Level 7
Joined
Apr 5, 2011
Messages
245
Note that you won't be able to use the dot syntax if you define it as an integer.
I can declare type extending integer and it seems to be fine with dot.

Thank you guys, but my question is most about destructor. If struct has unit, location, trigger variables they should be set null upon destroy as I have seen in a lot of spells otherwise it leaks. And my question is actually should I destroy integer/unit/location/trigger arrays (it seems very logic, isn't?)? What should I set null if I destroy arrays to prevent any leak? Like...
JASS:
private unit u
...
u.destroy()
set u = null
for...
JASS:
private integer array i[1023]
...
//???
and...
JASS:
private unit array u[1023]
...
//???
For using dot syntax I suggest...
JASS:
type my_integer_array extends integer array[1023]
type my_unit_array extends unit array[1023]
...that should replace arrays above.
 
Last edited:
Level 7
Joined
Apr 5, 2011
Messages
245
Bump. :p

edit
Solved. Found answer here.
In some way, this is syntax candy for declaring a new array type and making it a member of the struct, but this way is a little more optimizer and handles the array allocation/deallocation for you, with the exchange of some limitations.
The disadvantage of this method over declaring the dynamic array type separatedly is that you have less freedom in what concerns assigning to the member another array you create in other occation and things like that... The advantage is that it is faster and takes less code.
 
Last edited:
Status
Not open for further replies.
Top