• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Array Sizes - What do they do?

Status
Not open for further replies.
What? Oh.. Hold on..
ArraySizes.jpg

That?

What does that change?
 
Level 2
Joined
May 11, 2009
Messages
10
Read Illidans post "Initializes array[0] - array[size] with the initial value"

So if you have a value that is 10 and you check the array box and you set size 5 you will still have the full size array but the first 5 values will be 10.

Im not sure what the rest of the values will be 0? (or perhaps undefined?)

edit: If you have an array of objects (for example a new dialog as in your screenshot) Then it should be
as above: setting size 5 will give you the full array but only the first 5 locations will have a dialog in them.
 
Level 4
Joined
Apr 18, 2009
Messages
127
yes, yo ucould change something.

Say, you have a spawn system with several lvls.

You will for example have the integer with name

"Level"

Then you would have unit-type variable named

"Units"

And integer

"Amount"

So when level is 1 u set

Level[1]

That means that if you set

Units[1] = Peasant
Amount[1] = 5

This means that on level 1 you spawn 5 peasants

Now you may set Units[2] to another unit and another amount and so on
 
Level 18
Joined
Mar 7, 2005
Messages
824
I know it's solved, but just found something interesting in the net, that should clear it for all now (didn't saw any solution here):
Question:
Question:
What does the size of the array mean?
Answer:
Answer:
If you access a part of an array that you have not stored anything in yet, then Warcraft may crash or people may disconnect. If you set a size for your array, then the first entries in the array will be created and initialized for you. You can still add entries beyond the original size, but make sure you assign them before you access them.

Warcraft will actually allocate space for one more entry than you ask for. For example if set an array's size to 3, then entries 0, 1, 2, 3 will all be created. This is so you can start using the array at either 0 or 1 and still have 3 entries.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
I don't think warcraft crashes if you access part of the array. I'm sure it causes a thread crash, but won't cause a full crash I think.

The problem you're talking about is the following:

  • If index[20] = 0 then
    • ...
If you never used "Set index[20] = ..." then a crash will occur because the value is not initialized.

That's also what Illidan said: the number you enter in the variable editor is the amount of indices that are automatically initialized. So if you have an array of size 20, index 0 to 19 will be initialized (on map initialization, its value is set to default value).
 
I'm not really getting it. Put it in these terms. I have a dialog called Dialog.
I have a variable called DialogButton that is an array with a size one

I set a dialog and create six buttons labelled 1-6

Dialog (dialog)
1 (dialogbutton [1])
2 (dialogbutton [2])
3 (dialogbutton [3])
4 (dialogbutton [4])
5 (dialogbutton [5])
6 (dialogbutton [6])

Now what would change if i set the size to 2? is that like a whole other set of arrays?
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Nothing in your case.

Let me try to illustrate this with another example:

Say you have an integer array of size 5. Default value of 1.

  • For each integer A from 0 to 5 do:
    • Display string(intarray[Integer A]) to player 1
  • Display "Finished!" to player 1
This is what you'll see:
1
1
1
1
1

However, your trigger tells you to loop through 6 indices of the array, and display "finished" after doing so. Yet, you only see 5 ones and don't see "Finished"

The reason to this is that upon loading the map, warcraft 3 automatically sets intarray to the default value. But it only does so for the size you've specified. Since you specified a size of 5, warcraft initializes intarray[0] to intarray[4]. intarray[5] and above don't have any values at all.

Since intarray[5] isn't initialized, intarray[5] does not have a value. Its value is not 0, it's value is "nothing". Since warcraft can't display "nothing", the trigger crashes and stops running. Therefor, it doesn't show "Finished!".

Nevertheless, if you had first used "Set intarray[5] = 0" it would not have crashed because values [0] to [5] would have been initialized. You would then see following text:
1
1
1
1
1
0
Finished!

Your dialog works perfectly fine, because you've used "Set dialogbutton[1] = last created dialog button". In other words: your variables have values. If your variables don't have any values, warcraft doesn't know what to do.
 
Status
Not open for further replies.
Top