# What does the "array size" matter for?

#### thevoden

##### New Member
Whats the difference of setting the array size to 1 or to 7?

#### hi_im_bob

##### ......and you are?
Setting the Array size to 1 will only allow you to put in one value for the variable. Setting it to 7 will allow you to use 7 different values in a variable

#### duderock101

##### Check out my 2 Player Co-op RPG!
say you wanted to create two quest with one quest varible. You would put on the array 2. Then you'd do this

Code:
``````Quest - Create quest with title and description
Set Varible - Quest [1]
Quest - Create quest with title and description
Set Varible - Quest [2]``````

Plz plus rep if this helped

#### thevoden

##### New Member
I still don't get it.

I can set the variable array size to 1 and still be able to set the array number into different ones.

Whats stopping me from setting the questvariable to the array size of 1 in the trigger section and then doing the following trigger:

set variable - quest [ 1 ]
set variable - quest [ 2 ]
set variable - quest [ 3 ]

???

##### In need of sleep
from what ive experienced from useing variables....

if its one or over one, then the variable has an array

if its 0 then its not an array

thats all there is to it

#### thevoden

##### New Member
Can you explain that? Is there a difference to setting the variable array size of "setitems" to 3 than it is to setting it to 1?

so lets say I do set the following variables in the triggers:

set setitems [1] = claws
set setitems [2] = mask of death
set setitems [3] = potion

Would it matter if the array size was 1 or 3? If it doesn't then what is the difference between setting it to an array size? Why is there even an option to do this?

#### Flare

##### Stops copies me!
ìf the array size is 1, you arent able to do the above 3 set variables, since the array value of the second two exceed the array size of the variable.

if the array size is 3, itll work fine

so, to sum it up

Would it matter if the array size was 1 or 3? If it doesn't then what is the difference between setting it to an array size? Why is there even an option to do this?

yes, it does matter.

##### In need of sleep
tell you the truth, other then setting it to one, i have no clue.....

but.. in my mind....

i see the ability to but arrays in a variable as a booline (meaning its either true or false) if its 1 or >1 then it is true (meaning you can use the array with as many arrays as you want) if its 0 then its false (meaning that you cannot use arrays for that variable)

for evedence that i can use and unlimited ammount of arrays after setting it to one....

for almost all my maps, the player controlled unit is set under "hero[1]" meaning that its under the unit variable hero, and under an array size of one

i have 10 players

if it exeeded the array size by 9, then none of my maps would work, but they do work

if you want to challange me, go look for my maps in the members projects (not the invaders one because that is currently singleplayer only) and you will see what i mean.... or do you want me to upload a open version here so you can check

#### Ghan

##### Administrator - Servers are fun
Staff member
Has anyone actually tested this?
I just did with an Integer variable.

I set the size to 1, then stored 1, 2, and 3 in the indexes 1, 2, and 3.
Then I looped through them to display them on the screen.
It displayed all three.

So, if this does matter with something, I don't know what it is as it doesn't seem to affect the ability to store things in it.

I would guess that the size refers to the initial memory allocated to the variable, and that if you use more elements than you originally specified, it automatically assigns more memory.

#### SerraAvenger

##### Cuz I can
If you mean the Array size in the Variable Editor: The size only indicates which fields are initialised with the starting value you entered in the other field. Although you only set it to 5, you can use the array on 8192 fields later.

Like:
ThisIsAnExample Integer Array (4) 5

Would mean that the fields 1 - 4 are set to 5 in the map initialisation.
However, later in the code, you can still refer to
ThisIsAnExample[ 213 ]

The maximum value you can ever use is 8192, whatever you enter in the variable editor.
Hope that helped, Davey Jones.

#### 13est

##### New Member
I think I can make a good example.

As for my TD I got a variable that is called Level. It is an unit type variable with array 1-60.

When the map is started I have to set all arrays (I don't think there is another way)

Ex.
Set variable "Level [1]" = Footman
Set variable "Level [2]" = Ghoul

And after that the spawn trigger can be made.

Ex.

Spawn 1 unit of unit type "Level [x]"
(and after that)
Set variable "Level [x]" = "Level [x]" + 1

(I'm not sure, but I think you have to set Level = 1 first of all. )

It might look complicated, but these are not real triggers but just about how they look, and in the end it will look like this.

Spawn 1 unit of type "Level [1]" (footman)
Set variable "Level [1]" = "Level [1] + 1 (and that would be Level [2], so the next time the trigger runs it will be a ghoul)

Hope it helped a little bit.

#### thevoden

##### New Member
I know that.

I completely understand you. But in the TRIGGER editor itself, when you first create a variable, it gives you an ARRAY size. You can do all of the above setting the array to "1" and still be able to use what you were saying.

#### Knight7770

##### Hippopotomonstrosesquiped aliophobia
In that case, it's probably just there to make things easier to read while in the variable editor.

#### Slapshot136

##### Divide et impera
the array size is for what array #'s the "default" value is, isnt it? so like if you have an array of 3, then 0-3 have the default set and 4-8000 something dont have it set.. isnt it?

S

#### Slate.Master

##### Guest
I would guess that the size refers to the initial memory allocated to the variable, and that if you use more elements than you originally specified, it automatically assigns more memory.

Answered it all, IMO. It means that if you have a variable with array value = [1] but want to use variableX[2]/[3]/[4]/etc... the game auto creates the new arrays.

#### foodflare

##### You can change this now in User CP.
not always some arrays dont work that way, such as the timer window array.

#### AceHart

> not always, some arrays dont work that way

All arrays work that way.

The "difference" being that some variable types need to be created before you can use them.

As an example, if you create an array of unit groups of size 1,
the action "unit group - add unit" will work with groups 0 and 1 as soon as the maps starts,
but that same action on group 2 will fail, simply because there's no group there to put the unit into.
And, no, the game will not magically invent new content...

However, there's no problem to use:
Set array[2] = Units in <region> (or some other pick action) on that same size 1 array.

#### SerraAvenger

##### Cuz I can
And after that the spawn trigger can be made.

Ex.

Spawn 1 unit of unit type "Level [x]"
(and after that)
Set variable "Level [x]" = "Level [x]" + 1

Spawn 1 unit of type "Level [1]" (footman)
Set variable "Level [1]" = "Level [1] + 1 (and that would be Level [2], so the next time the trigger runs it will be a ghoul)

Hope it helped a little bit.

Actually this would not work most probably, although this is offtopic.
IF you want to make it work, use:
A gobal integer variable ( non array ) with the starting value 1, called LevelNumber
and in the trigger you would do this:
Code:
``````Spawn 1 unit of unit type "Level [ LevelNumber ]"
Set variable "LevelNumber" = "LevelNumber" + 1``````

What you actually did was not advance in the array ( like from Level[ 1 ] to Level[ 2 ] ) , but you increased the value hold b the field in the array by 1.
This means if it would've been Level[ 1 ] = 11212331, afterwards it would be:
Level[ 1 ] = 11212331 + 1 = 11212332
Hope that helped you too, Davey

#### Burningicce9

##### Cool Member
In other words....you will be fine if you just leave it at one.

General chit-chat
Help Users
• No one is chatting at the moment.
• The Helper:
I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
• The Helper:
What is up Old Mountain Shadow?
• The Helper:
Happy Thursday!
+1
• Varine:
Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
• Varine:
I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
• Varine:
Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
• Varine:
So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
• Varine:
I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
• Varine:
Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
• Varine:
Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
• Ghan:
Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
• The Helper:
Power back on finally - all is good here no damage
+2
• V-SNES:
Happy Friday!
+1
• The Helper:
New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
• The Helper:
I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
• The Helper:
Happy Wednesday!
+1
• V-SNES:
Happy Friday!
+1
• The Helper:
Sticking with the desserts for now the latest recipe is Fried Apple Pies - https://www.thehelper.net/threads/recipe-fried-apple-pies.194297/
• The Helper:
Finally finding about some of the bots that are flooding the users online - bytespider apparently is a huge offender here - ignores robots.txt and comes in from a ton of different IPs