• 🏆 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!

Variables array

Status
Not open for further replies.

hdm

hdm

Level 9
Joined
Nov 19, 2011
Messages
384
What are those Variables arrays ? 1,2,3,4,5... etc. How should I use them ? Are them trully useful?

I'm talking about GUI Trigger, I'm soooooooooooooooooooooooooooooooooooo baaaad with Jass. I just like this name cuz of the music style.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
Imagine normal variable as a building with 1 room only. This is nothing special right? Just one room, you may put something inside but that's about it.

An array would be one building that has many rooms. The same logic applies as with the 1 room-only building -> you can put some things inside each room.

But how do you find out in which room you have what? How do you differentiate those rooms? Well, you simply number them.
One room will have number 1, another room may have number 2, and so on.

The difference between building with 1 room and building with many rooms is obviously the amount of rooms each has. Of course you can create many buildings with 1 room, but really, why do it complicated when you can create 1 building with many rooms?

Basically that is the logic behind non-array and array variables.
You can save only 1 thing inside non-array variable; you can save more things inside array variable by giving it different indexes (numbers)

The advantage of using arrays is that you can easily access the data with simple code (mainly using loops), while using non-arrays forces you to manually add each variable you use.


Look at this bit of pseudo-code:
  • Set x1 = X of unit1
  • Set y1 = Y of unit1
  • Set x2 = X of unit2
  • Set y2 = Y of unit2
  • Set x3 = X of unit3
  • Set y3 = Y of unit3
  • Set x4 = X of unit4
  • Set y4 = Y of unit4
Basically you save X and Y coordinates of unit1-unit4
If you were to do this via arrays, then it would be like this:
  • For each integer variable loop_var from 1 to 4 do (Actions)
    • Loop
      • Set x[loop_var] = X of unit[loop_var]
      • Set y[loop_var] = Y of unit[loop_var]
This trigger is faster, easier to change and you won't get lost in it and it does exactly the same as the previous trigger.
 
Status
Not open for further replies.
Top