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

2d array help

Status
Not open for further replies.
Level 4
Joined
Jul 9, 2008
Messages
88
Currently Im working on a map where I need to keep track of whos allied to who, and to make things a lot easier I am trying to use 2d arrays which i have only recently heard about. This is my attempt, It may not be standard procedure for making it but I can t do the math to figure if it will work or bug.

Here goes. My 2d global variable is allied (boolean) [100]
  • allying
    • Events
      • Dialog - bla bla bla a button is clicked for _ dialogue is clicked by a player (1-10)
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Clicked dialog button) Equal to The right button
            • Then - Actions
              • Set allied[(((Player number of (Triggering player)) x 10) + ((Integer A) - 1))] = True
            • Else - Actions
      • Dialog - Clear bla bla bla
Its very diffficult for me to test this by my self, so i am asking you oh wise and mighty hiveworkshop.
 
Level 2
Joined
Jul 4, 2009
Messages
10
You need number of players of array[number of players] to store boolean alliance states, e.x:

Player1[16] Player2[16] Player[16] etc

If you insist on using 1D array, you need an array that is at least 12x12 in size.
 
Lets say we want to make a system for random item droping from a slain creature.

The system depends on two variable the creature level and the Hero level, those 2 variables will reflect the worthy of the item.

So, ItemDropped = ItemTable[HeroLevel][CreatureLevel] that for a 2d array.

But in GUI,

IF HeroLevel = 1
THEN ItemDroped = ItemTable1[CretureLevel]
ELSE

--

IF HeroLevel = 2
THEN ItemDroped = ItemTable2[CretureLevel]
ELSE

--

IF HeroLevel = 3
THEN ItemDroped = ItemTable3[CretureLevel]
ELSE



  • Init 10 Items
    • Events
    • Conditions
    • Actions
      • -------- Potions --------
      • -------- Healing Potions --------
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set HealingPotion[(Integer A)] = Minor Healing Potion
      • For each (Integer A) from 6 to 15, do (Actions)
        • Loop - Actions
          • Set HealingPotion[(Integer A)] = Light Healing Potion
      • -------- Mana Potions --------
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set ManaPotion[(Integer A)] = Mana Vial
      • For each (Integer A) from 6 to 15, do (Actions)
        • Loop - Actions
          • Set ManaPotion[(Integer A)] = Greater Mana Vial
      • -------- Items --------
      • -------- Set 1 --------
      • Set ItemSet1[1] = Ring of Energy
      • Set ItemSet1[2] = Ring of Intelligence
      • Set ItemSet1[3] = Ring of Strength
      • -------- Set 2 --------
      • Set ItemSet2[1] = Periapt of Vitality
      • Set ItemSet2[2] = Leather Armor
      • Set ItemSet2[3] = Ring of Attack
      • -------- Set 3 --------
      • Set ItemSet3[1] = Magi's medallion of life
      • Set ItemSet3[2] = Ring of Agility
      • Set ItemSet3[3] = Pebble of Life
      • -------- Gold --------
      • Set Gold[1] = 1 Gold
      • Set Gold[2] = 2 Gold
      • Set Gold[3] = 3 Gold
      • Set Gold[4] = 4 Gold
      • Set Gold[5] = 5 Gold
      • Set Gold[6] = 6 Gold
      • Set Gold[7] = 7 Gold
      • Set Gold[8] = 8 Gold
      • Set Gold[9] = 9 Gold
      • Set Gold[10] = 10 Gold
      • Set Gold[11] = 11 Gold
      • Set Gold[12] = 12 Gold
      • Set Gold[13] = 13 Gold
      • Set Gold[14] = 14 Gold
      • Set Gold[15] = 15 Gold
As you see I used more than a variable to create more than one set
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
I don't really understand the sense, too :eekani:


Say, every player got 5 heroes, and you dont want to make 12 variables, then you use 2d arrays.

JASS:
loop
    exitwhen i > 5
    set Hero[GetPlayerId(<Player>)*5 + i] = null
    set i = i + 1
endloop

Just an example, you can do a whole lot with it.
This example resets all your 5 heroes, as long as you are <Player>
 
Status
Not open for further replies.
Top