• 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.

Logical arithmetic for an incremental array?

Status
Not open for further replies.
Level 2
Joined
Jun 19, 2011
Messages
12
Okay, this one's a bit difficult to explain... I have an array of regions initialized to 24 indices. The first 8 contain player spawn locations, and every 2 elements that follow define a short group of locations where creeps should spawn. I really enjoy having it set up like this, because I can access any region in the game from a single variable. In terms of optimization, It's worked extremely well for every trigger I've written. But I ran into a logical epidemic, and I need your help...

Here's an example of the way the array is initialized:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Hero spawn locations --------
      • Set SpawnLocations[1] = P1 <gen>
      • Set SpawnLocations[2] = P2 <gen>
      • Set SpawnLocations[3] = P3 <gen>
      • Set SpawnLocations[4] = P4 <gen>
      • Set SpawnLocations[5] = P5 <gen>
      • Set SpawnLocations[6] = P6 <gen>
      • Set SpawnLocations[7] = P7 <gen>
      • Set SpawnLocations[8] = P8 <gen>
      • -------- Creep spawn locations (For P1) --------
      • Set SpawnLocations[9] = Gate 1 to 5 <gen>
      • Set SpawnLocations[10] = Gate 1 to 6 <gen>
      • -------- Creep spawn locations (For P2) --------
      • Set SpawnLocations[11] = Gate 2 to 5 <gen>
      • Set SpawnLocations[12] = Gate 2 to 7 <gen>
      • -------- Creep spawn locations (For P3) --------
      • Set SpawnLocations[13] = Gate 3 to 6 <gen>
      • Set SpawnLocations[14] = Gate 3 to 8 <gen>
      • -------- Creep spawn locations (For P4) --------
      • Set SpawnLocations[15] = Gate 4 to 7 <gen>
      • Set SpawnLocations[16] = Gate 4 to 8 <gen>
      • -------- Creep spawn locations (For P5) --------
      • Set SpawnLocations[17] = Gate 5 to 1 <gen>
      • Set SpawnLocations[18] = Gate 5 to 2 <gen>
      • -------- Creep spawn locations (For P6) --------
      • Set SpawnLocations[19] = Gate 6 to 1 <gen>
      • Set SpawnLocations[20] = Gate 6 to 3 <gen>
      • -------- Creep spawn locations (For P7) --------
      • Set SpawnLocations[21] = Gate 7 to 2 <gen>
      • Set SpawnLocations[22] = Gate 7 to 4 <gen>
      • -------- Creep spawn locations (For P8) --------
      • Set SpawnLocations[23] = Gate 8 to 3 <gen>
      • Set SpawnLocations[24] = Gate 8 to 4 <gen>
As you can see, it's exactly as I described. And for single increments (between 1-8 for players, and 9-24 for creeps) it works great.

BUT HERE'S my problem...
In a For/Loop (1-8), I'm trying to access a random number between 9 and 10 on the first loop, then 11 and 12 on the next, 13 and 14 on the next, and so on...
  • Spawn
    • Events
      • Time - SpawnTimer expires
    • Conditions
    • Actions
      • -------- Iterate through each player --------
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • -------- Is this person actually playing? --------
              • OnlineUsers[(Integer A)] Equal to True
            • Then - Actions
              • -------- Figure out which region to spawn creeps in for this player --------
              • Set TempInt = (Random integer number between 0 and 1)
              • Set TempRegion = SpawnLocations[( PERHAPS SOME KIND OF MIND-BLOWING ARITHMETIC? (+ TempInt?) )]
              • -------- Spawn the creeps --------
              • Unit - Create 1 Creeps for Player 9 (Gray) at (Center of TempRegion) facing Default building facing degrees
              • Unit Group - Pick every unit in (Units in TempRegion owned by Player 9 (Gray)) and do (Actions)
                • Loop - Actions
                  • Unit - Order (Picked unit) to Attack-Move To (Center of SpawnLocations[(Integer A)])
            • Else - Actions
              • Do nothing
SO... is it possible to step through the loop like this? Would I need to rewrite my entire project using hashtables instead? Is there a better way of doing this? Perhaps something incredibly simple that I've overlooked!?... My brain's on overload lately.
 
Level 7
Joined
May 13, 2011
Messages
310
After a bit of thinking I've got it. What you want to do is add 2, multiplied by your Integer A, to 8. And then you subtract TempInt from it.
Not sure how good that explanation was, but here's the action anyway:

  • Set TempRegion = SpawnLocations[((8 + (2 x (Integer A))) - TempInt)]
That should do the trick. Not exactly mind-blowing, but I can how it can be overlooked, it did take me a few minutes to get it.
 
Level 2
Joined
Jun 19, 2011
Messages
12
You, good sir, are a logical genius... Thanks!
Kind of a curve ball, eh? Funny thing is, I knew it would be simple math. But after trying more than 6 equations and order of operations, as well as completely rewriting the code twice, I felt like an idiot haha!
+Rep to you!
 
Status
Not open for further replies.
Top