Problems with Counting Instances of a Value in an Array

0 favourites
  • 3 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • Hey everyone! What I'm trying to do is count how many times a certain value appears in an array, and set a variable to that number. Here's the code I have:

    What happens in the array is that when you pick up a carrot or potato, they are added to the Inventory array at an index of 0.

    Now, the code above works fine when I pick up the same object, such as 3 potatoes, but once I pick up a carrot the variables both become equal to the same number when they shouldn't be. For example, if I pick up 2 carrots the CarrotCount variable becomes 2. Then, when I

    pick up 1 potato, both the CarrotCount and PotatoCount variables become 3.

    Does anyone know why this is happening and how I can fix it?

    Thank you!

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Inventory contains value is a general check whether it exists, not whether it exists at the curx, it should be array curx = "CarrotInv" as the condition. Inventory contains value is a check you would do if you wanted to know if any carrots existed in the array for example.

  • That fixed it, thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)