• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Efficient way to use Arrays

Status
Not open for further replies.
Level 13
Joined
Jan 2, 2016
Messages
978
I HAVE EDITED MY EXAMPLE WITH A NEW ONE, AS THE OLD EXAMPLE WAS NOT REALISTIC
(I will use a spell that I made on a map, while learning how to use triggers.)

Ever had to make a custom MUI ability, that has several levels and uses Unit Groups? If yes, then it most likely looked something like this:
  • Mana Flare
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Mana Flare Hero
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Mana Flare Hero for (Triggering unit)) Equal to 1
        • Then - Actions
          • Unit Group - Add (Target unit of ability being cast) to ManaFlare1Group[(Player number of (Owner of (Triggering unit)))]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Mana Flare Hero for (Triggering unit)) Equal to 2
            • Then - Actions
              • Unit Group - Add (Target unit of ability being cast) to ManaFlare2Group[(Player number of (Owner of (Triggering unit)))]
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Mana Flare Hero for (Triggering unit)) Equal to 3
                • Then - Actions
                  • Unit Group - Add (Target unit of ability being cast) to ManaFlare3Group[(Player number of (Owner of (Triggering unit)))]
                • Else - Actions
  • Mana Flare Effect
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • ((Triggering unit) has buff Mana Flare (Extra)) Equal to True
    • Actions
      • For each (Integer FlareLoop2) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is in ManaFlare1Group[FlareLoop2]) Equal to True
            • Then - Actions
              • Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
              • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
              • Unit - Cause (Last created unit) to damage (Triggering unit), dealing 15.00 damage of attack type Spells and damage type Cold
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is in ManaFlare2Group[FlareLoop2]) Equal to True
            • Then - Actions
              • Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
              • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
              • Unit - Cause (Last created unit) to damage (Triggering unit), dealing 30.00 damage of attack type Spells and damage type Cold
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is in ManaFlare3Group[FlareLoop2]) Equal to True
            • Then - Actions
              • Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
              • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
              • Unit - Cause (Last created unit) to damage (Triggering unit), dealing 45.00 damage of attack type Spells and damage type Cold
            • Else - Actions
Well, that's quite annoying, isn't it?
Instead you can just do:
VERSION 1:
  • Mana Flare
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Mana Flare Hero
    • Actions
      • For each (Integer FlareLoop1) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Mana Flare Hero for (Triggering unit)) Equal to FlareLoop1
            • Then - Actions
              • Unit Group - Add (Target unit of ability being cast) to ManaFlareGroup[((((Player number of (Owner of (Triggering unit))) - 1) x 3) + FlareLoop1)]
            • Else - Actions
  • Mana Flare Effect
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • ((Triggering unit) has buff Mana Flare (Extra)) Equal to True
    • Actions
      • For each (Integer FlareLoop2) from 1 to 12, do (Actions)
        • Loop - Actions
          • For each (Integer FlareLoop3) from 1 to 3, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Triggering unit) is in ManaFlareGroup[(((FlareLoop2 - 1) x 3) + FlareLoop3)]) Equal to True
                • Then - Actions
                  • Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
                  • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
                  • Unit - Cause (Last created unit) to damage (Triggering unit), dealing (15.00 x (Real(FlareLoop3))) damage of attack type Spells and damage type Cold
                • Else - Actions
VERSION 2:
  • Mana Flare
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Mana Flare Hero
    • Actions
      • For each (Integer FlareLoop1) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Mana Flare Hero for (Triggering unit)) Equal to FlareLoop1
            • Then - Actions
              • Unit Group - Add (Target unit of ability being cast) to ManaFlareGroup[(((FlareLoop1 - 1) x 12) + (Player number of (Owner of (Triggering unit))))]
            • Else - Actions
  • Mana Flare Effect
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • ((Triggering unit) has buff Mana Flare (Extra)) Equal to True
    • Actions
      • For each (Integer FlareLoop2) from 1 to 12, do (Actions)
        • Loop - Actions
          • For each (Integer FlareLoop3) from 1 to 3, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Triggering unit) is in ManaFlareGroup[(((FlareLoop3 - 1) x 12) + FlareLoop2)]) Equal to True
                • Then - Actions
                  • Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
                  • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
                  • Unit - Cause (Last created unit) to damage (Triggering unit), dealing (15.00 x (Real(FlareLoop3))) damage of attack type Spells and damage type Cold
                • Else - Actions
Much simpler! Imagine if you had to make 10 unit groups for just one skill. This will save you tons of writing, and you will have less variables to deal with!

NOTES:
1) This technique can be used for Units and for Items too, it's not limited to Unit Groups.
2) Using the "normal way" takes many variables with 13 levels (or 12 if you are writing -1), while this method takes 12*(groups needed per player)+1. Don't forget to make your arrays big enough.
3) The number "*3" in this example varries, based on how many levels the ability has, if it has 9 levels, it should be changed to 9.

EDIT:
Wietlol reminded me that I didn't EXPLAIN what I was doing, and I just showed what to do, therefore I will add this to the Original post :p
If you want to use multiple dimensional arrays (you do have a reason for it otherwise you wouldnt be here), then you can make one array and calculate the total length of one of the dimensions.

For example, you want to store 5 variables per player.
Then you have a max of either 5 (5 variables) or 16 (16 players).
Visualizing the data would make a table of 5x16:
xPlayer 1Player 2Player 3Player 4Player 5Player 6Player 7Player 8Player 9Player 10Player 11Player 12Player 13Player 14Player 15Player 16
Variable 1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Variable 2
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Variable 3
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Variable 4
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Variable 5
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

Any cell can be accessed by the formula (x + y*XMAX).
XMAX is a constant defining the maximum length of a row (16).
x and y are the coordinates in their axis.

So variable 2 of player 9 will be
x = 8 (because player 1 is the 0th index)
y = 1 (because variable 1 is the 0th index)
XMAX = 16
x + y*XMAX = 8 + 1*16 = 24.
Now you count the slots in the table and find out that counting from left to right, from top to bottom, starting at 0, 24 will be the second variable of player 9.

Optionally, you can do the same formula backwards:
Index = (x + y*XMAX)
y = Index / XMAX (Because it is an integer, it will be rounded down to the nearest round number.)
x = ModuloInteger(Index, XMAX) < Modulo is a function in WE (But also everywhere else)

Now, you can make one array that will contain all your pretty data for every player.
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,658
1, this shouldnt be in WEHZ as you are not asking for help on your stuff but are trying to help other people... tutorial section?

2, "If you know how to use Hashtables, you can stop reading now (unless you still use arrays a lot)."
Please dont tell me when to stop reading... I stop reading whenever I see that you write bull shit... then I continue to tell you it was bull shit... like this post :D

3, let me explain the bull shit:
If you know how to use hashtables, then stop using them and start using arrays.
Hashtables are only better than arrays if you want to have a practical limitless list, a list with multiple dimensions where the factor of all dimensions is larger than 8190 or when you need a list of stuff stored on an index larger then 8190.
In EVERY SINGLE OTHER CASE, you use arrays.

4, We do not use "every 1 second of gametime" in randomly added units (stuff).
Simply because you will have a slightly lower interval as first and last steps between 0 and 1.
We either use different timers or we use a 0.03-0.05s timer and allocate the data in array (!!!ARRAYS!!!) storing the duration it requires to complete the second.

5, How you use unit groups is just... I dont know how to say it... bad is not enough but the word that I want to describe it with will get me banned.

6, Your explanation is not really clear... even to me... uhm... not many people can explain something to me, but how simple this is should be very clear to me.

7, Im out.

Btw, if you were an elf, then you should be able to write something usefull... at least the elves I have in mind are beings of higher knowledge... you... not so much. Sorry :/
 
Level 13
Joined
Jan 2, 2016
Messages
978
1, this shouldnt be in WEHZ as you are not asking for help on your stuff but are trying to help other people... tutorial section?

2, "If you know how to use Hashtables, you can stop reading now (unless you still use arrays a lot)."
Please dont tell me when to stop reading... I stop reading whenever I see that you write bull shit... then I continue to tell you it was bull shit... like this post :D

3, let me explain the bull shit:
If you know how to use hashtables, then stop using them and start using arrays.
Hashtables are only better than arrays if you want to have a practical limitless list, a list with multiple dimensions where the factor of all dimensions is larger than 8190 or when you need a list of stuff stored on an index larger then 8190.
In EVERY SINGLE OTHER CASE, you use arrays.

4, We do not use "every 1 second of gametime" in randomly added units (stuff).
Simply because you will have a slightly lower interval as first and last steps between 0 and 1.
We either use different timers or we use a 0.03-0.05s timer and allocate the data in array (!!!ARRAYS!!!) storing the duration it requires to complete the second.

5, How you use unit groups is just... I dont know how to say it... bad is not enough but the word that I want to describe it with will get me banned.

6, Your explanation is not really clear... even to me... uhm... not many people can explain something to me, but how simple this is should be very clear to me.

7, Im out.

Btw, if you were an elf, then you should be able to write something usefull... at least the elves I have in mind are beings of higher knowledge... you... not so much. Sorry :/

1) I'm still new to the forum, sorry :p
2) What I meant was that Hashtables can replace this way doing things completely.
3) But perhaps you are right, arrays might be better if you don't need to store huge amount of variables.
4) This was just an example I have already made all my triggers the way I suggested here, and didn't feel like making a realistic example, so I just wrote something basic to show how this way uses formula to calculate the damage instead of multiple Ifs.
5) As you might have figured it out in (4), That's not the way I really use unit groups... Just couldn't be bothered to make a realistic example, but fine, I will post a trigger that I am using:
  • Magic Cluster Damage
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Magic Cluster Bolt
    • Actions
      • Custom script: local unit u = GetSpellTargetUnit()
      • For each (Integer Magic_Cluster_Damage_Loop[(Player number of (Owner of (Triggering unit)))]) from 1 to 9, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Target unit of ability being cast) is in Mag_Cluster_Group[((Magic_Cluster_Damage_Loop[(Player number of (Owner of (Triggering unit)))] x 12) + (Player number of (Owner of (Triggering unit))))]) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Magic_Cluster_Damage_Loop[(Player number of (Owner of (Triggering unit)))] Less than 9
                • Then - Actions
                  • Unit Group - Add (Target unit of ability being cast) to Mag_Cluster_Group[(((Magic_Cluster_Damage_Loop[(Player number of (Owner of (Triggering unit)))] + 1) x 12) + (Player number of (Owner of (Triggering unit))))]
                • Else - Actions
              • Unit Group - Remove (Target unit of ability being cast) from Mag_Cluster_Group[((Magic_Cluster_Damage_Loop[(Player number of (Owner of (Triggering unit)))] x 12) + (Player number of (Owner of (Triggering unit))))]
              • Wait ((Distance between (Position of (Triggering unit)) and (Position of (Target unit of ability being cast))) / 1200.00) seconds
              • Custom script: set udg_Mag_Cluster_Target = u
              • Unit - Cause (Triggering unit) to damage Mag_Cluster_Target, dealing ((Mag_Cluster_Damage[Magic_Cluster_Damage_Loop[(Player number of (Owner of (Triggering unit)))]] / 100.00) x (35.00 + (65.00 x (Real((Level of Magic Cluster Bolt for (Triggering unit))))))) damage of attack type Spells and damage type Magic
              • Floating Text - Create floating text that reads ((String(Mag_Cluster_Damage[Magic_Cluster_Damage_Loop[(Player number of (Owner of (Triggering unit)))]], 1, 2)) + %) above Mag_Cluster_Target with Z offset 0.00, using font size 10.00, color (75.00%, 50.00%, 25.00%), and 0.00% transparency
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Set the velocity of (Last created floating text) to 70.00 towards 90.00 degrees
              • Floating Text - Change the fading age of (Last created floating text) to 4.00 seconds
              • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
              • Skip remaining actions
            • Else - Actions
This trigger was using 8 Ifs before. The way it is now is much shorter.
NOTES:
1) This spell uses 2 triggers, but I didn't want to post the other one as it's too long, but the way the spell works is: it creates dummies, who fire this "Magic Cluster Bolt" Multiple times. So the units get damaged by different amount for each bolt they take.
2) This way the spell is MUI, so if 2 (or more) players use this spell at once, on the same targets - the damage from other players' bolts woudln't change the damage of your bolts (and vice versa).

EDIT:
I actually found a trigger that is only half using this system, so I can demonstrate how much shorter it makes the triggers. Do have in mind that before this trigger was 4 times longer (I was using 4x item arrays, instead of just one. I don't need to use loop for this one as I am just checking how many items has the player already obtained and just give him the next one), and now it will become (in total) 12 times shorter than it originally was. AND I can add more "treasures", without making the trigger any longer.
  • treasure digging
    • Events
      • Player - Player 1 (Red) types a chat message containing -dig as An exact match
      • Player - Player 2 (Blue) types a chat message containing -dig as An exact match
      • Player - Player 3 (Teal) types a chat message containing -dig as An exact match
      • Player - Player 4 (Purple) types a chat message containing -dig as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -dig as An exact match
      • Player - Player 6 (Orange) types a chat message containing -dig as An exact match
      • Player - Player 7 (Green) types a chat message containing -dig as An exact match
      • Player - Player 8 (Pink) types a chat message containing -dig as An exact match
      • Player - Player 9 (Gray) types a chat message containing -dig as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -dig as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing -dig as An exact match
      • Player - Player 12 (Brown) types a chat message containing -dig as An exact match
    • Conditions
      • game_time Greater than or equal to 1.00
      • Or - Any (Conditions) are true
        • Conditions
          • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)]) Equal to True
          • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)]) Equal to True
          • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 3)]) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (treasure <gen> is on) Equal to True
          • Item_order[40] Not equal to <Empty String>
        • Then - Actions
          • Trigger - Turn off treasure <gen>
          • Trigger - Turn off Randomizer <gen>
        • Else - Actions
      • Set treasure_digged[(Player number of (Triggering player))] = True
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)]) Equal to True
        • Then - Actions
          • Unit - Pause heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)]
          • Wait 5.00 seconds
          • Unit - Unpause heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)] is alive) Equal to True
            • Then - Actions
              • Hero - Create treasure_rewards[((((Player number of (Triggering player)) - 1) x Items_amount) + (treasure_count[(Player number of (Triggering player))] + 1))] and give it to heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)]
              • Game - Display to (All players) the text: (((Name of (Triggering player)) + ('s + (Proper name of heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)]))) + (( has found + (Name of (Last created item))) + !))
              • Set treasure_found[(Player number of (Triggering player))] = True
              • Set treasure_count[(Player number of (Triggering player))] = (treasure_count[(Player number of (Triggering player))] + 1)
              • Trigger - Run treasure hunt <gen> (ignoring conditions)
            • Else - Actions
              • Game - Display to (Player group((Triggering player))) the text: Your hero died befo...
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)]) Equal to True
            • Then - Actions
              • Unit - Pause heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)]
              • Wait 5.00 seconds
              • Unit - Unpause heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)] is alive) Equal to True
                • Then - Actions
                  • Hero - Create treasure_rewards[((((Player number of (Triggering player)) - 1) x Items_amount) + (treasure_count[(Player number of (Triggering player))] + 1))] and give it to heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)]
                  • Game - Display to (All players) the text: (((Name of (Triggering player)) + ('s + (Proper name of heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)]))) + (( has found + (Name of (Last created item))) + !))
                  • Set treasure_found[(Player number of (Triggering player))] = True
                  • Set treasure_count[(Player number of (Triggering player))] = (treasure_count[(Player number of (Triggering player))] + 1)
                  • Trigger - Run treasure hunt <gen> (ignoring conditions)
                • Else - Actions
                  • Game - Display to (Player group((Triggering player))) the text: Your hero died befo...
            • Else - Actions
              • Unit - Pause heroes[((((Player number of (Triggering player)) - 1) x 3) + 3)]
              • Wait 5.00 seconds
              • Unit - Unpause heroes[((((Player number of (Triggering player)) - 1) x 3) + 3)]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (heroes[((((Player number of (Triggering player)) - 1) x 3) + 3)] is alive) Equal to True
                • Then - Actions
                  • Hero - Create treasure_rewards[((((Player number of (Triggering player)) - 1) x Items_amount) + (treasure_count[(Player number of (Triggering player))] + 1))] and give it to heroes[((((Player number of (Triggering player)) - 1) x 3) + 3)]
                  • Game - Display to (All players) the text: (((Name of (Triggering player)) + ('s + (Proper name of heroes[((((Player number of (Triggering player)) - 1) x 3) + 3)]))) + (( has found + (Name of (Last created item))) + !))
                  • Set treasure_found[(Player number of (Triggering player))] = True
                  • Set treasure_count[(Player number of (Triggering player))] = (treasure_count[(Player number of (Triggering player))] + 1)
                  • Trigger - Run treasure hunt <gen> (ignoring conditions)
                • Else - Actions
                  • Game - Display to (Player group((Triggering player))) the text: Your hero died befo...
      • Set treasure_digged[(Player number of (Triggering player))] = False
  • treasure digging
    • Events
      • Player - Player 1 (Red) types a chat message containing -dig as An exact match
      • Player - Player 2 (Blue) types a chat message containing -dig as An exact match
      • Player - Player 3 (Teal) types a chat message containing -dig as An exact match
      • Player - Player 4 (Purple) types a chat message containing -dig as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -dig as An exact match
      • Player - Player 6 (Orange) types a chat message containing -dig as An exact match
      • Player - Player 7 (Green) types a chat message containing -dig as An exact match
      • Player - Player 8 (Pink) types a chat message containing -dig as An exact match
      • Player - Player 9 (Gray) types a chat message containing -dig as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -dig as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing -dig as An exact match
      • Player - Player 12 (Brown) types a chat message containing -dig as An exact match
    • Conditions
      • game_time Greater than or equal to 1.00
      • Or - Any (Conditions) are true
        • Conditions
          • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 1)]) Equal to True
          • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 2)]) Equal to True
          • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + 3)]) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (treasure <gen> is on) Equal to True
          • Item_order[40] Not equal to <Empty String>
        • Then - Actions
          • Trigger - Turn off treasure <gen>
          • Trigger - Turn off Randomizer <gen>
        • Else - Actions
      • Set treasure_digged[(Player number of (Triggering player))] = True
      • For each (Integer digging_loop[(Player number of (Triggering player))]) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (treasure_region[(Player number of (Triggering player))] contains heroes[((((Player number of (Triggering player)) - 1) x 3) + digging_loop[(Player number of (Triggering player))])]) Equal to True
            • Then - Actions
              • Unit - Pause heroes[((((Player number of (Triggering player)) - 1) x 3) + digging_loop[(Player number of (Triggering player))])]
              • Wait 5.00 seconds
              • Unit - Unpause heroes[((((Player number of (Triggering player)) - 1) x 3) + digging_loop[(Player number of (Triggering player))])]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (heroes[((((Player number of (Triggering player)) - 1) x 3) + digging_loop[(Player number of (Triggering player))])] is alive) Equal to True
                • Then - Actions
                  • Hero - Create treasure_rewards[((((Player number of (Triggering player)) - 1) x Items_amount) + (treasure_count[(Player number of (Triggering player))] + 1))] and give it to heroes[((((Player number of (Triggering player)) - 1) x 3) + digging_loop[(Player number of (Triggering player))])]
                  • Game - Display to (All players) the text: (((Name of (Triggering player)) + ('s + (Proper name of heroes[((((Player number of (Triggering player)) - 1) x 3) + digging_loop[(Player number of (Triggering player))])]))) + (( has found + (Name of (Last created item))) + !))
                  • Set treasure_found[(Player number of (Triggering player))] = True
                  • Set treasure_count[(Player number of (Triggering player))] = (treasure_count[(Player number of (Triggering player))] + 1)
                  • Trigger - Run treasure hunt <gen> (ignoring conditions)
                • Else - Actions
                  • Game - Display to (Player group((Triggering player))) the text: Your hero died befo...
              • Set treasure_digged[(Player number of (Triggering player))] = False
              • Skip remaining actions
            • Else - Actions
And what this does is: in the begining of the game, I shuffle 4 items (could make them more in the future) and hide them in different regions. So when a player has a hero in the correct region and writes "-dig" - he digs out the treasure. Then another trigger hides the next treasure in another region :)
Player 1 may collect the treasures like: 3-rd, 1-st, 4-th, 2-nd, Player 2 may collect like: 1-st, 4-th, 2-nd, 3-rd, etc... different players get the treasures in different order, and different players have their treasures hidden in different regions.
 
Last edited:
Moved to Lab.

A group of something abstracts the sum of unique objects for you.
It is a helper because you easily can for example iterate through all of these objects.

But when it comes to unique damage for example for one of these unique objects (unit in this example),
it is better if you bind the damage directly to the unit and don't try to solve it indirectly with seperating the abstract thing "unit group".

What I try to say is that why to bother with arraying unit groups,
when you could just do so with the damage directly.

Try to have only one unit group -> it lets you iterate through all your units.
Try to have unique damage for each unit -> it lets you have unique damage. (yes, Captain obvious told me :D)

This could be or solved with using a helping system, a UnitIndexer,
or you just create a unique index for your system by yourself.
And the final trigger would look similar like this then:
Code:
Loop Units:
    - Deal Damage[Index] to Target[Index]
So only one data structure is used for iterating, not multiple ones.
But instead the Damage is a variable with an array. It is more intuitive.

As said to get a unique index a UnitIndexer can be used, or many users also use this tequnique: http://www.hiveworkshop.com/forums/...orials-279/visualize-dynamic-indexing-241896/

Btw, what is also negative point of the shown Group[array] method is that
it seems it is hardcoded to level amount and players. It isn't flexible. :/
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
2) What I meant was that Hashtables can replace this way doing things completely.
Yes but hashtables are less efficient.
They have a larger limit so that is where you want to use them, not just because you can.

3) But perhaps you are right, arrays might be better if you don't need to store huge amount of variables.
They are better especially when you want to store huge amounts of variables because the efficiency is more obvious when you compare 1000 hashtable loads to 1000 array loads.

5) As you might have figured it out in (4), That's not the way I really use unit groups... Just couldn't be bothered to make a realistic example, but fine, I will post a trigger that I am using:
Waits are quite bad... especially when you use them to wait the duration of a missiles flight.
The first part of your loop will not work properly in later iterations because of the wait as well.
I suggest you to use a system to do things that are done multiple times...
In this case a missile system would work perfectly.



Also, you wanted to clarify the use of multiple dimensional arrays.
I would say this would be enough:

If you want to use multiple dimensional arrays (you do have a reason for it otherwise you wouldnt be here), then you can make one array and calculate the total length of one of the dimensions.

For example, you want to store 5 variables per player.
Then you have a max of either 5 (5 variables) or 16 (16 players).
Visualizing the data would make a table of 5x16:
xPlayer 1Player 2Player 3Player 4Player 5Player 6Player 7Player 8Player 9Player 10Player 11Player 12Player 13Player 14Player 15Player 16
Variable 1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Variable 2
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Variable 3
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Variable 4
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Variable 5
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

Any cell can be accessed by the formula (x + y*XMAX).
XMAX is a constant defining the maximum length of a row (16).
x and y are the coordinates in their axis.

So variable 2 of player 9 will be
x = 8 (because player 1 is the 0th index)
y = 1 (because variable 1 is the 0th index)
XMAX = 16
x + y*XMAX = 8 + 1*16 = 24.
Now you count the slots in the table and find out that counting from left to right, from top to bottom, starting at 0, 24 will be the second variable of player 9.

Optionally, you can do the same formula backwards:
Index = (x + y*XMAX)
y = Index / XMAX (Because it is an integer, it will be rounded down to the nearest round number.)
x = ModuloInteger(Index, XMAX) < Modulo is a function in WE (But also everywhere else)

Now, you can make one array that will contain all your pretty data for every player.
 
Level 13
Joined
Jan 2, 2016
Messages
978
Any cell can be accessed by the formula (x + y*XMAX).
XMAX is a constant defining the maximum length of a row (16).
x and y are the coordinates in their axis.

So variable 2 of player 9 will be
x = 8 (because player 1 is the 0th index)
y = 1 (because variable 1 is the 0th index)
XMAX = 16
x + y*XMAX = 8 + 1*16 = 24.
Now you count the slots in the table and find out that counting from left to right, from top to bottom, starting at 0, 24 will be the second variable of player 9.

Optionally, you can do the same formula backwards:
Index = (x + y*XMAX)
y = Index / XMAX (Because it is an integer, it will be rounded down to the nearest round number.)
x = ModuloInteger(Index, XMAX) < Modulo is a function in WE (But also everywhere else)

Now, you can make one array that will contain all your pretty data for every player.
Wait... wasn't that EXACTLY what I was doing? Just.. I used 12 players instead of 16 as I am not really gonna allow creeps to use the custom spells :p
Or were you just trying to explain what I was doing to people who are looking at this thread and not understanding what's going on?
 
Status
Not open for further replies.
Top