I have an array of "unit type", i use this array as a parameter into a trigger.
Now, to loop through it i have to know its size, how can i obtain this information? (let's say i want set an int variable with the size of this array).
(since the function im developing must be map-independent i can't just write the size of the array, changing it all the time).
I think if you're adding/removing entries from the array it'd be at those points you also have another int variable that's being incremented and decremented to track the size of it and use that variable as your 'top value' when doing a for loop. That's how you'd handle such things in other programming languages at least.
I can't know the size of the array, that array is a parameter of my custom action.
My action will use that array, received as parameter, to do something else.
My question is how to loop through an array of which i don't know the size?
I mean, that in Java would be arrayName.length, thats simply what i need to know.
@wolflisk
Actions
General - For each integer i from 0 to 15 with increment 1, do (Actions
The point of the problem is how to know that "15" without writing it, there must be some abstract way to get it.
Sorry, fraid most languages aren't as forgiving as java and this appears to be one of them. Believe me if you made the array and the actions that built it, you could figure out how big it is too.
Well when creating the array you should set it to what you want. You can't change it ingame. The way my code works is that it only uses the parts that it needs, and so effectively changes the array size. Complicated, but works. I'd recommend setting it to an array of size 100 or so and then using some code similar to what i posted earlier and limiting the allowed array values.
Sorry, fraid most languages aren't as forgiving as java and this appears to be one of them. Believe me if you made the array and the actions that built it, you could figure out how big it is too.
the problem is that i am not supposed to build the array, i just write my custom action which uses it.
That action will not be map-related, and it is not said will be used only on my maps, so i cant say how big is the array.
All i have to do is loop through it.
The structure of the custom action is :
-parameter : the array
-actions : loop through the array and do something for each i.
that's all, kind of basic stuff.
I guess the only way is to add another int parameter with the size of the array.
Nite01, what w0lf and the others are trying to tell you is there is no such thing as a pointer in SCII, therefore there is no such thing as dynamic memory allocation, and no such thing as a variable array. I have not tried, but I am prety sure you cannot pass an array as a parameter...
That being said... You can always do a "for each X in Y" loop for anything you don't know the quantity of, or you can do a while loop (an infinite loop) that exits when you run out of "things"
Anyway, if you want some "abstract" way of getting the array length.. generally you create a global constant integer and set it to the size of your array. Then use this constant. It's easier to change array lengths then.
As i said, it is impossible to change the size of an array ingame. Or if it is in a mod. However, it is possible to limit the array slots used using a method like mine (the one i posted was for effectivly setting an array size to the amount of players).
Before you pass your array to another function you must declare it. What size do you have it declared for.
Then you set values in your array at the pre-defined Indexs 0- what ever you set the size for
Then you pass your array to a function as a parameter. (when referencing the array in your function the array will have the same size limitations that the array had when creating it.) ..... That is if you can even pass arrays I havent tried but im sure it wouldnt be a problem.
I think you mean you might have values in the array that are not set. That is fine in your function you pass your array to you must code it so that it can handle Null values at any index of your array.
If you can not understand it at this point I suggest you give up mapping.
I have an array of "unit type", i use this array as a parameter into a trigger. Now, to loop through it i have to know its size, how can i obtain this information? (let's say i want set an int variable with the size of this array). (since the function im developing must be map-independent i can't just write the size of the array, changing it all the time).
Thanks for help,
Nite
I think if you're adding/removing entries from the array it'd be at those points you also have another int variable that's being incremented and decremented to track the size of it and use that variable as your 'top value' when doing a for loop. That's how you'd handle such things in other programming languages at least.
@Nite01: Go
Set an array of size 15 and then do this:
Then use that var as the size of the array. Anything above it will still be there, just unused. And this should work for 1-16 players.
Bump is correct, although the OP wasn't asking for a stack structure. You can use a variable to track the operating size of the array.
@OneSoga: Go
arrays have a set size in the editor, it doesn't change while runnning. You have to know it.
I can't know the size of the array, that array is a parameter of my custom action. My action will use that array, received as parameter, to do something else. My question is how to loop through an array of which i don't know the size?
I mean, that in Java would be arrayName.length, thats simply what i need to know.
@wolflisk Actions General - For each integer i from 0 to 15 with increment 1, do (Actions
The point of the problem is how to know that "15" without writing it, there must be some abstract way to get it.
Thanks for help!
Nite
Sorry, fraid most languages aren't as forgiving as java and this appears to be one of them. Believe me if you made the array and the actions that built it, you could figure out how big it is too.
@Nite01: Go
Well when creating the array you should set it to what you want. You can't change it ingame. The way my code works is that it only uses the parts that it needs, and so effectively changes the array size. Complicated, but works. I'd recommend setting it to an array of size 100 or so and then using some code similar to what i posted earlier and limiting the allowed array values.
the problem is that i am not supposed to build the array, i just write my custom action which uses it. That action will not be map-related, and it is not said will be used only on my maps, so i cant say how big is the array. All i have to do is loop through it.
The structure of the custom action is :
-parameter : the array
-actions : loop through the array and do something for each i.
that's all, kind of basic stuff.
I guess the only way is to add another int parameter with the size of the array.
Thanks everyone by the way!
Nite01, what w0lf and the others are trying to tell you is there is no such thing as a pointer in SCII, therefore there is no such thing as dynamic memory allocation, and no such thing as a variable array. I have not tried, but I am prety sure you cannot pass an array as a parameter...
That being said... You can always do a "for each X in Y" loop for anything you don't know the quantity of, or you can do a while loop (an infinite loop) that exits when you run out of "things"
1. Map array is not dynamic. You will define it yourself at design time. There's no need to get it since you will always know it beforehand
2. If you need to know filled array size, you can always use an integer variable to keep track
Can't you just pass the length of the array into the function as a parameter?
YourFunction(Array AnArray, Int ArrayLength);
Can't pass arrays as parameters.
Anyway, if you want some "abstract" way of getting the array length.. generally you create a global constant integer and set it to the size of your array. Then use this constant. It's easier to change array lengths then.
@Nite01: Go
you will have an other problem: AFAIK can't you give an array as paramter to a function/actionlist.
Edit:
@s3rius: Go
Too late... :)
@Thenarden: Go
As i said, it is impossible to change the size of an array ingame. Or if it is in a mod. However, it is possible to limit the array slots used using a method like mine (the one i posted was for effectivly setting an array size to the amount of players).
SC2 Galaxy Editor uses a modified C, wich neither is Object-Orientated nor has dynamic alocated arrays... too bad :(
To the Poster
I think you mean you might have values in the array that are not set. That is fine in your function you pass your array to you must code it so that it can handle Null values at any index of your array.
If you can not understand it at this point I suggest you give up mapping.