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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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