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

Question about ARRAYS

Status
Not open for further replies.
Level 7
Joined
Sep 11, 2013
Messages
220
I was wondering if the Arrays of variables work with 5 players if its number is only 1? like: UNIT[1] and in the triggers i can set it to UNIT[1,2,3,4,5].

The reason Im asking this is because I want to make my map less slow and lag.

Thats it, thanks...
 
I still don't understand. If you have some variable:
  • Set Unit[1] = (Triggering unit)
well... then you would use Unit[1] to refer to it.

If you set it to the player's index:
  • Set Unit[(Player number of (Triggering player))] = (Triggering unit)
Then you would refer to it with Unit[Player number of <Player>]. So it would be either Unit[1] for Player 1, Unit[2] for Player 2, Unit[3] for player 3, etc...

I'm still not sure what the question is.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
JASS arrays (which are the implementation type GUI generates when you save) have no defined size. They are vectors/dynamic arrays that will automatically expand as larger array indices are required. The only limit being that indices are bound in the range of 0 and 8191 (inclusive). There is a bug with index 8191 which causes problems with game saves. The buffer used to store the array cannot contract, it will only ever expand so you should try and keep indexes continuous where possible.

The size parameter of GUI arrays is only used for initializing the state of an array during map initialization. It firstly guarantees that once the map loads, the array will have expanded to be that size and that all elements up to size index will be initialized to the provided value.

As such the size parameter is completely useless if you know the array indices will always be written to first before being read. This most likely matches your problem since you will be setting the unit array to some units at a later time than map initialization so a unit array with size 1 will work perfectly.

There are a few cases where arrays do need initial size in GUI. Specifically the case with timers since I recall there being no action to create new timers in GUI so you have to depend on the size of the array to generate the timer objects at map initialization.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
You don't have to se the initial size of arrays. They work without it.

Note that unit groups, timers, dialogs, player groups and stuff like that are automatically created for indexes upto the initial value.

For example if you create a timer array, and set the initial value to 2, there will be timers created automatically for indexes 0, 1 and 2. But if you try to start a timer at index 3, nothing will happen as it is not created.
 
Status
Not open for further replies.
Top