| 11-22-2003, 09:00 PM | #1 |
How do you create local arrays? It sounds really stupid but I've never had to do it before. The reason I need it is because for a spell I've got there are several different local unit variables being used. I thought it'd save time if I could just make an array and call things from it. |
| 11-22-2003, 09:13 PM | #2 |
function MyFunc takes .... returns .... local integer array MyIntArray local unit array MyUnitArray endfunction Remember, local arrays can't be set to initial value. |
| 11-22-2003, 09:25 PM | #3 |
But global can? How? |
| 11-22-2003, 09:35 PM | #4 |
No they can't. Not first cell nor other can be set to initial values without using special code. |
| 11-22-2003, 11:18 PM | #5 |
integers are zero and booleans are false by default though |
| 11-22-2003, 11:33 PM | #6 |
Thanks for telling me. One more thing. When setting global arrays you need to set the 'size' of the array. Is this just not required for locals? |
| 11-22-2003, 11:43 PM | #7 |
And handle-type arrays contain null as default data :) I'm not sure about boolean arrays - I gues empty cells contains null even for boolean arrays. (?) Boolean array cells can be compared with null but can't be set to. But it's impossible anyway to set initial value other than default... 35263526: You don't need to set array size anyway. It's only GUI trick - array size is limited only by JASS_MAX_ARRAY_SIZE constant which is equal to 1024 in RoC and 8192 in TFT. |
| 11-23-2003, 12:08 AM | #8 |
What the size does is make it so it initially loops through and sets those elements of the array to an initial value, like 0 instead of null. |
| 11-23-2003, 12:15 AM | #9 |
JASS scripting doesn't need these GUI tricks :) As for NULL, it is equal to integer 0 because handle is just integer points to memoty location. This is my ihmo, and I may be wrong... |
| 11-23-2003, 05:13 AM | #10 | |
Quote:
Well, it is wrong, sorry. NULL means there is no allocated memory for the variable. Zero is an actual value at a memory location. |
| 11-23-2003, 10:24 AM | #11 | |
Quote:
It would be interesting to know how you know that. |
| 11-23-2003, 10:36 AM | #12 |
Handles are integers that point to a place in the handle array (not directly to a memory location as that would be much too unsafe). Well, to settle that use the type conversion bug and look what null turns into (my bet is 0). |
| 11-23-2003, 12:03 PM | #13 |
Nozdormu: Let's test following function: Code:
function WhoIsRight takes nothing returns nothing local integer array TestArray set TestArray[0] = 0 if TestArray[0] == null then call DisplayTextToForce(GetPlayersAll(), "null is a pointer equal to 0") else call DisplayTextToForce(GetPlayersAll(), "null is something else :)") endif endfunction 2 AIAndy: I guess the same - null is just handle equal to 0. |
