• 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.

[General] different struct arrays

Status
Not open for further replies.
Level 17
Joined
Jul 17, 2011
Messages
1,863
Hai
is there any difference when you:

1. Have a normal struct and create an array member of that struct like this:
JASS:
struct A1
integer c 
endstruct
// 
globals
A1 array bla
endglobals
set bla[0].c = 0 
set bla[1].c = 55 
...

2. And create a struct that extends an array and use it:
JASS:
struct ABC extends array 
integer c
endstruct 
//
globals

endglobals
set ABC [0].c = 1 
set ABC [1].c = 999


ive been getting some weird errors when using the first method like data being "shared" by members of different array struct types created from 1 struct so anyone know if these two are any different when the struct array is used as a global variable ?
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
I never saw something like that, and I think the second wouldnt even compile, but I cant say for sure because I never tried it.(Reason being that J is not in fact array, its simple integer as any other integer)

extends array only removes the custom allocate, deallocate, create, destroy methods and you have to declare all of them by ourself. Also extends array can be used if you dont want to instanciate your struct or want to make your own more complex or maybe lighter allocate method

Your problem with first example is that none of your instances are created, which means this for c with bla[0] is 0 and for bla[1] is also 0, you can test this by printing the struct instance using something like BJDebugMsg(I2S(bla[0]))
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
oh yea, now it makes a lot more sence :D the thing you do differently in second then in first is that in first you are trying to use the same instance over and over again(always 0) and in the second example you are saying: set c for instance 0 to 0, set c for instance of 1 to 55, basically the array index is the instance number, which is not changing in first example because you didnt create the instances(either calling .allocate() inside, or .create() from utside, .allocate() is private)
 
Status
Not open for further replies.
Top