Loop for counting part 2.

Exide

I am amazingly focused right now!
Reaction score
448
Hi.

I made a thread about counting number of items (strings) a few weeks ago.
Siretu helped me and my triggers works great.
There is a small problem, though.

The trigger Siretu made for me does something like this:
*takes one item
*finds another one
*stacks them together
*forget the first item
*repeat until there are no more items of the same type

This is good except for one thing:
When I try to access InventoryAmount[*] it returns "0"
If I got 6 items of "Type A" the list will look something like this:

InventoryAmount[1] = 0
InventoryAmount[2] = 0
InventoryAmount[3] = 0
InventoryAmount[4] = 0 //All six of these are the same type of item
InventoryAmount[5] = 0
InventoryAmount[6] = 6

So my triggers (aka me) is having trouble knowing where to look for the correct array for each item.

Here are the triggers:

Trigger:
  • InventoryItemCheckAmount
    • Events
    • Local Variables
      • loop = 0 <Integer>
      • secondloop = 0 <Integer>
      • checkname = "" <String[99]>
    • Conditions
    • Actions
      • General - For each integer loop from 1 to 99 with increment 1, do (Actions)
        • Actions
          • Variable - Set InventoryAmount[loop] = 0
      • General - For each integer loop from 1 to 99 with increment 1, do (Actions)
        • Actions
          • Variable - Set checkname[loop] = InventoryItem[loop]
          • General - For each integer secondloop from 1 to 99 with increment 1, do (Actions)
            • Actions
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • checkname[secondloop] == checkname[loop]
                  • checkname[secondloop] != ""
                • Then
                  • Variable - Set InventoryAmount[secondloop] = (InventoryAmount[secondloop] + 1)
                  • General - If (Conditions) then do (Actions) else do (Actions)
                    • If
                      • loop != secondloop
                    • Then
                      • Variable - Set checkname[loop] = ""
                    • Else
                • Else



In another trigger I'm doing this:
(In the following trigger I have used another trigger to create buttons, that is why I have to loop through them all to check which one is used.)

Trigger:
  • Inventory UseItem
    • Events
      • Dialog - Any Dialog Item is used by Player Any Player with event type Clicked
    • Local Variables
      • loop = 0 <Integer>
    • Conditions
      • CombatCheck == False
    • Actions
      • General - For each integer loop from 1 to 99 with increment 1, do (Actions)
        • Actions
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • (Used dialog item) == InventoryItemUseButton[loop]
            • Then
              • Trigger - Run Inventory Set UseItemStats (Ignore Conditions, Don't Wait until it finishes)
              • Trigger - Turn (Current trigger) Off
              • Variable - Set UsedItem = InventoryItem[loop]
              • Variable - Set UsedItemNumber = loop
              • Dialog - Set MenuUseItemDialogItem[5] text to ("Choose hero to use " + (("<c val="00FFFF">" + ((Text(UsedItem)) + "</c>")) + " on.")) for (All players)
              • Dialog - Show MenuUseItemDialog for (All players)
              • Dialog - Show MenuUseItemStatsDialog for (All players)
              • General - Break
            • Else


and finally, I'm trying to use the info in a third trigger:

Trigger:
  • General - If (Conditions) then do (Actions) else do (Actions)
    • If
      • InventoryAmount[UsedItemNumber] <= 0
    • Then
      • ------- No more items of that type, closing the pop-up screens
      • Variable - Set UsedItem = ""
      • Dialog - Hide MenuUseItemDialog for (All players)
      • Dialog - Hide MenuUseItemStatsDialog for (All players)
      • Trigger - Turn Inventory UseItem On
    • Else


The variables to look out for are:
InventoryAmount[], UsedItemNumber and UsedItem
the rest of the code is not important.

What happens:
In the third trigger, I can't find the correct InventoryAmount[] array value: resulting in the game returning 0 and "closing the pop-up screens."



EDIT: I think I have found the problem, but I'm not sure how to fix it.
In this trigger:

Trigger:
  • Menu Inventory
    • Events
    • Local Variables
      • usebuttoncheck = False <Boolean>
      • loop = 0 <Integer>
      • i = 35 <Integer>
    • Conditions
    • Actions
      • Trigger - Turn Open Menu Off
      • Trigger - Run InventoryItemCheckAmount (Ignore Conditions, Don't Wait until it finishes)
      • General - For each integer loop from 1 to 99 with increment 1, do (Actions)
        • Actions
          • Dialog - Destroy InventoryItemLabelName[loop]
          • Dialog - Destroy InventoryItemLabelDescription[loop]
          • Dialog - Destroy InventoryItemLabelAmount[loop]
          • Dialog - Destroy InventoryItemLabelValue[loop]
          • Dialog - Destroy InventoryItemUseButton[loop]
      • General - For each integer loop from 1 to 99 with increment 1, do (Actions)
        • Actions
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • InventoryItem[loop] != ""
            • Then
              • Variable - Set usebuttoncheck = (InventoryUseButtonCheck(InventoryItem[loop]))
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • usebuttoncheck == True
                • Then
                  • General - If (Conditions) then do (Actions) else do (Actions)
                    • If
                      • CombatCheck == False
                    • Then
                      • ------- Create "Use" Button
                      • Dialog - Create a button for dialog MenuInventoryDialog with the dimensions (50, 23) anchored to Top Left with an offset of (40, (85 + i)) setting the tooltip to "" with button text "Use" and the hover image set to ""
                      • Variable - Set InventoryItemUseButton[loop] = (Last created dialog item)
                    • Else
                • Else
              • Dialog - Create a label for dialog MenuInventoryDialog with the dimensions (200, 50) anchored to Top Left with an offset of (100, (85 + i)) with the text (Text(InventoryItem[loop])) color set to White text writeout set to False with a writeout duration of 0.0
              • Variable - Set InventoryItemLabelName[loop] = (Last created dialog item)
              • Dialog - Create a label for dialog MenuInventoryDialog with the dimensions (400, 50) anchored to Top Left with an offset of (300, (85 + i)) with the text (Text((InventoryItemGetDescription(InventoryItem[loop])))) color set to White text writeout set to False with a writeout duration of 0.0
              • Variable - Set InventoryItemLabelDescription[loop] = (Last created dialog item)
              • Dialog - Create a label for dialog MenuInventoryDialog with the dimensions (200, 50) anchored to Top Left with an offset of (700, (85 + i)) with the text (Text(InventoryAmount[loop])) color set to White text writeout set to False with a writeout duration of 0.0
              • Variable - Set InventoryItemLabelAmount[loop] = (Last created dialog item)
              • Dialog - Create a label for dialog MenuInventoryDialog with the dimensions (200, 50) anchored to Top Left with an offset of (900, (85 + i)) with the text (Text((InventoryItemValueCheck(InventoryItem[loop])))) color set to White text writeout set to False with a writeout duration of 0.0
              • Variable - Set InventoryItemLabelValue[loop] = (Last created dialog item)
              • Variable - Set i = (i + 20)
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • InventoryAmount[loop] == 0
                • Then
                  • Dialog - Destroy InventoryItemLabelName[loop]
                  • Dialog - Destroy InventoryItemLabelDescription[loop]
                  • Dialog - Destroy InventoryItemLabelAmount[loop]
                  • Dialog - Destroy InventoryItemLabelValue[loop]
                  • Dialog - Destroy InventoryItemUseButton[loop]
                  • Variable - Set i = (i - 20)
                • Else
            • Else
      • Dialog - Show MenuInventoryDialog for (All players)


When I create "Use" buttons -I believe I create one button for each item (unlike Siretu's count trigger which stack items and remove the other value). Meaning for six items of the same type I create six different buttons. When I then loop through them all my trigger finds the first button and reacts to it; setting UsedItemNumber to that number - when the item is actually stacked up on number six.
I believe adding a way to remove unnecessary buttons created this way will fix my problem.
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
Instead of removing the unnecessary buttons I would just make sure I don't create the unnecessary buttons. Since the unnecessary buttons are those with an InventoryItemAmount of 0, I would just have an if-then-else check before I create it and just creating the button if InventoryItemAmount[item] != 0.

However, this system feels like it will get messier over time. I am hesitant to even have the same item type take up several indices in the array depending on how many there are. Are the items actually going to be stacked? Is there a reason to not just have the item only occur once in the InventoryItem[] array.

Example: I have a potion and an ether. So my InventoryItem looks like this:

InventoryItem[1] = "potion"
InventoryItem[2] = "ether"

Now if I acquire an additional potion, your system would add a potion to InventoryItem[3], correct?(Again, I have no idea how the map actually works so this might not be the case at all). So it would add:

InventoryItem[3] = "potion"

I suggest instead of doing that, you loop through the InventoryItem[] and see if the string is already in the array. If it is, you add 1 to the InventoryItemAmount in the index you found the string.

If you want to go even further, you could make a record(which is kind of like a struct, if you know what that is) and have it store both the name(string), amount(integer) and maybe even the unit-type if you want to save the actual type of the item.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top