What I mean is, does an array of size in SC2 1 mean an array that contains a single element (Array[0]) or an array that contains 2 (Array[0], Array[1])?
I'd believe the latter but it gives the option of having an array of size 0. As arrays are hopefully static in SC2, setting an array to size 0 would make it so it could never hold any elements but I'm sure there are some uses for a null array if that is allowed in SC2.
The arrays offer the possibility of multiple dimensions but I'm not sure how to use SC2's gui to make a 2 dimensional array.
I'd like to declare an array that holds arrays of type integer (an array of (arrays of integers)) which would look like:
Don't think there's a way to do this without a workaround, since we don't have pointers in galaxy. The closest solution I can think of to this is to store the numbers in a comma delimited string "0,1,2", then write a function to extract specific elements from it.
But let's say that every player is allowed up to six heroes, so I have to store each hero as well each hero's attributes.
I'd use a 1-d Unit Array[6] Heroes and then a 2-d int Array[6][6] stats and just match the indices to know which index of the Heroes corresponds to the index of the int Array:
Not sure what the question is there, but a better way would be to use records (structs) as they allow you to declare properties of different types.
It's declared as such in script, I don't know how it's done in GUI as I don't use it.
structhero{int[6]stats;};hero[6]struct_hero;
When you want to callback the stats, just refer to the struct: struct_hero[ hero_index ].stats[stat_index]
PS: I forgot to mention this in my earlier post, its actually a way you could pull off what you're trying to do as it is similar to an array in an array.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hi everyone,
Where does the indexing start for arrays in SC2?
What I mean is, does an array of size in SC2 1 mean an array that contains a single element (Array[0]) or an array that contains 2 (Array[0], Array[1])?
I'd believe the latter but it gives the option of having an array of size 0. As arrays are hopefully static in SC2, setting an array to size 0 would make it so it could never hold any elements but I'm sure there are some uses for a null array if that is allowed in SC2.
The arrays offer the possibility of multiple dimensions but I'm not sure how to use SC2's gui to make a 2 dimensional array.
I'd like to declare an array that holds arrays of type integer (an array of (arrays of integers)) which would look like:
Array[0] = IntArray{0,1,2} Array[1] = IntArray{5,112,79} Array[2] = IntArray{10000, 99584, 6543} etc...
Thanks!
@sethmachine: Go
contains a single element (Array[0])
This. Arrays are 0 indexed. So an array of size 1, starts at index 0.
Array[0] = IntArray{0,1,2} Array[1] = IntArray{5,112,79} Array[2] = IntArray{10000, 99584, 6543} etc...
Don't think there's a way to do this without a workaround, since we don't have pointers in galaxy. The closest solution I can think of to this is to store the numbers in a comma delimited string "0,1,2", then write a function to extract specific elements from it.
@FuzzYD: Go
I haven't worked with arrays in awhile but how then do multi dimensional arrays work?
Array[n] (size here) has n elements
Then If I did int Array[6][6] (both numbers are sizes not indices here) at each index of the array there are six additional possible indices?
int Array[3][3] a
a[0][0] = 72 a[0][1] = 1567 ... a[5][5] = 2632
I've done image manipulation by representing pixels/their colors in 3-d arrays and that's how it worked...
@sethmachine: Go
int Array[3][3] a
Yeah, that's how they work. I usually avoid them like the plague though, as they can get very hard to keep track of.
@FuzzYD: Go
But let's say that every player is allowed up to six heroes, so I have to store each hero as well each hero's attributes.
I'd use a 1-d Unit Array[6] Heroes and then a 2-d int Array[6][6] stats and just match the indices to know which index of the Heroes corresponds to the index of the int Array:
Heroes[0] information is stored in stats[0]
etc...
@sethmachine: Go
Not sure what the question is there, but a better way would be to use records (structs) as they allow you to declare properties of different types.
It's declared as such in script, I don't know how it's done in GUI as I don't use it.
When you want to callback the stats, just refer to the struct: struct_hero[ hero_index ].stats[stat_index]
PS: I forgot to mention this in my earlier post, its actually a way you could pull off what you're trying to do as it is similar to an array in an array.