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

Shift units in an array easily GUI

Status
Not open for further replies.
Level 9
Joined
Oct 17, 2009
Messages
370
So I was thinking about some ideas for heroes I had and began wondering about if there is a way to easily shift all units inside an array by 1, say I make an array containing 6 units. I remove the first unit with index 0, then move the rest of the 5 from 1-5 to 0-4.
It's easily doable by assigning the units to a temporary array and then back with 1 less index, but is there an easier way?
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
But I thought arrays are fast. D:

At least compared to hashtables.

twice as fast actually, since a hashtable is a 2d array and a array is well, just an array. (and the fact that you tend to call functions to get the keys)

OT:
Sadly there is no way to get the array size directly. So you need to store that into a variable.

Loop from 0/1 to X and set your array to:
something[integer A/B - 1] = something[integer A/B]
@death Before you comment on it, I KNOW that integer a/b is slower.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
twice as fast actually, since a hashtable is a 2d array and a array is well, just an array. (and the fact that you tend to call functions to get the keys)

A hashtable read / write is actually about 4-8 times slower than an array read / write. That means when looping through about 2-6 array indexes that the hashtable is a faster more efficient method. (Don't forget the ITE checks when looping through an array.)
 
Status
Not open for further replies.
Top