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

[Trigger] Handling 2 arrays in one integer

Status
Not open for further replies.
Level 16
Joined
Mar 26, 2004
Messages
569
Hi, i'm trying to make a sort of inventory with multiple pages (yeah i know it's been done before, but i can only find it in JASS).

So my problem is:

I want to store the items carried in slot 1-5 which is simply
  • For each (Integer A) from 1 to 5, do (Actions)
    • Loop - Actions
      • Set Item[(Integer A)] = (Item-type of (Item carried by Unit <gen> in slot (Integer A)))
But with that, i can't distinguish which page i am on. Do i need to make a variable for each page? Like:
  • Set ItemPage1[(Integer A)] = (Item-type of (Item carried by Unit <gen> in slot (Integer A)))
 
Level 4
Joined
Jun 1, 2007
Messages
92
Use an integer variable to distinguish which page you are on, then set the items to whatever.
  • go to next page
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to NEXT PAGE
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Page Equal to 1
        • Then - Actions
          • Set Page = 2
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Set Item[(Integer A)] = (Item carried by Blood Mage 0000 <gen> in slot (Integer A))
              • Item - Move (Item carried by Blood Mage 0000 <gen> in slot (Integer A)) to (Center of Region 000 <gen>)
          • For each (Integer A) from 6 to 10, do (Actions)
            • Loop - Actions
              • Hero - Give Item[(Integer A)] to Blood Mage 0000 <gen>
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Page Equal to 2
        • Then - Actions
          • Set Page = 1
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Set Item[((Integer A) + 5)] = (Item carried by Blood Mage 0000 <gen> in slot (Integer A))
              • Item - Move (Item carried by Blood Mage 0000 <gen> in slot (Integer A)) to (Center of Region 000 <gen>)
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Hero - Give Item[(Integer A)] to Blood Mage 0000 <gen>
        • Else - Actions
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Yes, you can distinguish which page you are on - First, store all your pages in the same array!

Slots 1-6 are page 1.

7-12 are page 2.

13-18 are page 3.

Etc.

(or 0-5,6-11,12-17 if you start from 0 index)

Formula: Inventory index + 6*(page-1)

Thus, the (the index - the modulus of the index by 6)/6 + is the page you are on, assuming you know what index you are looking from. (Or you could just find it via looping through the array, but that isn't the fastest - compare slot 0 to array slots 0,6,12,18,etc).

Or you could store the page in an integer, this way is more memory efficient but a little weirder.
 
Status
Not open for further replies.
Top