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 The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      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