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

Variable Sizes

Status
Not open for further replies.
As bear said, it is arrays. It just function as many variables as it's array size. They are considerably easier to traverse than x individual variables. For instance, if you want each player to have points, instead of making 10 individual variables, you can create a single array variable with a size of 10. Where you just use something like:
Points[GetPlayerIndex(player)]
to get a specific players points.
 
Variable sizes only matter if you're playing around with initial value of the variable (which I highly advise not to do). They let you automatically store an initial value into an array, which is what variable size means. For example:

If you have an integer variable called TempInt that will store the number 5 in 6 different locations, you make the variable size 6, and it will automatically store the number 5 into 6 different locations.
  • TempInt[0] = 5
  • TempInt[1] = 5
  • TempInt[2] = 5
  • TempInt[3] = 5
  • TempInt[4] = 5
  • TempInt[5] = 5

You can always leave variable size and initial value their default values and just edit them inside a trigger like this (which is a recommended way of doing it):
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set TempInt[0] = 5
    • Set TempInt[1] = 5
    • Set TempInt[2] = 5
    • Set TempInt[3] = 5
    • Set TempInt[4] = 5
    • Set TempInt[5] = 5
    • -------- --------
    • -------- c-c-combo breaker for more efficient way of doing it --------
    • For each (LoopInt) from 0 to 5, do (Actions)
      • Loop - Actions
        • Set TempInt[LoopInt] = 5

EDIT: Wow you guys all beat me :( this is what I get for trying to make my post look nice.
 
Level 14
Joined
Nov 30, 2013
Messages
926
Thanks for your help guys but it's still doesn't help for my problem.

I know arrays btw but the sizes was actually I'm talking about is this.
234345-albums7856-picture105033.png

I'm sorry if I confused you guys or this is actually you guys telling me about.
 
That is just the max size of the arrays. Aka, you can never set or get the value of a variable with size n, for a array position greater than n. So if you have a variable "PlayersI" with size 4, you can never use "PlayersI[5]" or bigger.
NOT true...

array size is importand to set more then 1 only in few cases like
Timer
UnitGroup
PlayerGroup

If you need 5 timers for example you have to set Timer array to size: 5


but always set array size to 1 for Integers, Reals, Locations, booleans etc
If you have TempInteger array variable, you declare it to size 1.
You can use in triggers for example TempInteger[5] or TempInteger[2000] (up to 8191)
zibi
 
Level 13
Joined
Jan 2, 2016
Messages
978
NOT true...

array size is importand to set more then 1 only in few cases like
Timer
UnitGroup
PlayerGroup

If you need 5 timers for example you have to set Timer array to size: 5


but always set array size to 1 for Integers, Reals, Locations, booleans etc
If you have TempInteger array variable, you declare it to size 1.
You can use in triggers for example TempInteger[5] or TempInteger[2000] (up to 8191)
zibi

So making an array with size 1 makes it as big as an array with size 8191?
(If it's integer/real/etc)
 
Level 12
Joined
May 22, 2015
Messages
1,051
NOT true...

array size is importand to set more then 1 only in few cases like
Timer
UnitGroup
PlayerGroup

If you need 5 timers for example you have to set Timer array to size: 5


but always set array size to 1 for Integers, Reals, Locations, booleans etc
If you have TempInteger array variable, you declare it to size 1.
You can use in triggers for example TempInteger[5] or TempInteger[2000] (up to 8191)
zibi

You can still get around that as long as you create the objects yourself, can't you? You may need to use JASS to do that, though. I know I've used CreateGroup() quite a bit, anyway.

The thing is that the arrays are always gigantic (0-8191). Setting the size in the world editor just causes it to initialise up to that many indexes. It is important with the non-primitive variables since you can't just start adding units to a group that doesn't exist, but primitives are all basically just integers so it doesn't matter what they start out as.

Units as nulls are handled nicely with almost all (or maybe all) functions, so maybe this is why it doesn't matter if you define them or not.

Anyway, the reason to not set their size is because setting the size adds a loop to the map initialisation function that loops up to the size you define and sets the values for all those indexes. This is a lot of things to do. While it is probably mostly negligible in terms of how long it takes, it is basically wasted time.

The bigger issue, though, is the operation limit. Every time a function does something, it adds an operation. When you hit the limit, the game aborts the function. I think it is to prevent infinite loops or something like that. If you want to test it out, try making like 10 arrays with size 8000 in your map. The variable initialisation happens before your trigger initialisation, so it is possible that your initialisation function hits the operation limit and aborts before it even builds your triggers. You get some pretty odd errors when this happens.
 
Level 12
Joined
May 22, 2015
Messages
1,051
So what exactly does that mean? GUI users (who don't know JASS) should still set their variables to the size they'd need, or they can just set their arrays to 1?

Ya for GUI I think you need to set the size for the ones listed by ZiBitheWand3r3r, but otherwise you are okay.

I wanted to ask if it is necessary or if it is just because it will crash unless you initialise them yourself (which I think requires JASS). Then I just rambled on about how it works and why you should avoid setting the size above 1 as much as possible (basically any time it is not one of the ones listed).
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
The arrays will always have the 8192 size.
However, at the map initialization, you can fill your arrays with default values, like an empty group or an idle timer.
You can set these values for normal variables very easily, however for arrays it doesnt make much sense to make 8192 unit groups if you only need 12 for example.
So you can set the total number of slots in the array that will be set to the default value.

If you set a unit group array to a size of 10, the first 10 (0-9) will have an empty unit group. If you want to use more, then you have to create more unit groups and add those to the array. The size wont limit you to that size.

I kind of disrecommend to use default values in the first place but for GUI usage of timers and groups it may prove useful.
 
Status
Not open for further replies.
Top