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

[Solved] How to index an array variable?

Status
Not open for further replies.
Level 14
Joined
Aug 8, 2010
Messages
1,022
Hello, mates! I wanna ask, how do i index an array variable? I'll give an example :
If i have Effect1, Effect2 and Effect3, put them in an indexing variable :
Effect1[Array] = Effect1
Effect2[Array] = Effect2
Effect3[Array] = Effect3
i can manipulate them by simply using EffectX[Array]. But how do i do the same if the non-indexed EffectX variables are converted into one with array? Example :
If i have Effects[1 or 2 or 3] (i'll refer to this variable as Effects[X]) instead of Effect1, Effect2 and Effect3, how do i index Effects[X]? Does it have to be something like this :

For loop (Integer A) from 1 to 3 do :
Effects[[IntegerA [Array]] = Effect_IntegerA (i can do this because i load the values from a hashtable, i load a string, thus i can use concatenate strings : Effect + String(IntegerA) )

I tried this (which is the same as the thing above) :
  • Set CSEArray[CArray] = (Integer A)
  • Set CSpecialEffects[CSEArray[CArray]] = Load bla bla bla EffectIntegerA
I was able to manipulate the effects successfully but it wasn't MUI which was the main point... :sad:

Thanks in advance!!! :thumbs_up:
Help is appreciated with +rep !
 
Level 14
Joined
Aug 8, 2010
Messages
1,022
I had no internet for a hour or so and the hashtable idea got in my mind. Then i saw here that it is truly a way of solving the problem.
Something like that:
  • Hashtable - Save Handle Of(Last created special effect) as 2 of 5 in (Last created hashtable)
To save.

and
  • Special Effect - Destroy (Load (Integer A) of (Integer B) in (Last created hashtable))
To load effect.
So basically Integer A is the effect's index while Integer B is the spell's index, is this right?
 
JASS:
// Imagine you have global unit array named U
unit array U

//Also imagine you want to add some special effect to it
unit_add_special_effect( unit, effect )

// now that above is simple function created for this example, 
// but GUI actions works like that as well, 
// this above will add effect to unit, simple as that.

// in game when you create units you can do something like

set U[1] = CreateUnit(....) //jass example
set U[2] = bj_lastCreatedUnit //In GUI you work with this
set U[3] = U[1] //another example and so on

// finally you use them like this
unit_add_special_effect( U[2], effect ) //Add to 2nd unit effect

// loop looks like
integer i = 1
loop
     exitwhen i == 10
     unit_add_special_effect( U[i], effect )
     set i = i + 1
endloop
// this will add same effect to first 10 units

// but what about 2D or 3D arrays...
// for small ones you can go single array like this

set your_array[ indexA * 1000 + indexB] = something...

// so for indexA from 0 to 4, and indexB from 1 to 3 you should have:
// 
//     1     2     3
// 1001 1002 1003
// 2001 2002 2003
// 3001 3002 3003
// 4001 4002 4003
//
// same for 3D and so on, but it's hard to write example ^_^
// end for the end take note that array in wc3 go up to 8192.
// so indexA x indexB x indexN < 8192
 
Level 14
Joined
Aug 8, 2010
Messages
1,022
@-Kobas- i did the hashtable way before reading what you said.. it works this way though. It happened to be really easy. Perhaps i can use what you said somewhere else where i need to do indexing like this. Thanks! :)

To the rest of you, THANKS! I used Starquizer's solution and it works perfectly!
THANKS!
 
Level 14
Joined
Aug 8, 2010
Messages
1,022
In GUI, first comes the child key and then the parent key. When flushing data, you use the parent key. So in your case it looks like A = child, B = parent.

If you're never going to flush the data then it doesn't matter.
What did you mean by "flushing" data? I saw there was an action that clears all child hashtables, etc. Is this a flush?
Well, i use A as a child and B as a parent and the only thing i do is to recycle.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Well, the array of the spell (Integer B) increases, decreases, and then increases again, thus it overwrites. If the data is overwritten it will not cripple stuff a lot, right?

Flushing is done when the hashtable is not used even for a while, for example, in spells when all instance of it has finished and is not in use, that way would make the memory more dynamic. As long as you are reading/writing data from/into a hashtable no flush is needed.
 
Status
Not open for further replies.
Top