Checking the number of a value in an array

  • Hi,

    I added an one dimensional array (width:4, height:1, depth:1) which has 4 cells. And with floor(random(9)) expression filled the cells which the numbers from 0 to 9.

    I want to check how many times a value exists in this array.

    So I created attached event. My problem is, this event continuosly add 1 to global variable X. I want to check the array once and then stop.

    As an example, if the array cells are (1,4,4,7) and I want to check how many 4's are placed in the array (in this example 2), how can I do it.

    Thanks in advance...

    Tagged:

  • Add a triggering condition to your top level event, the one with the for each element. For example on button pressed or on click or something.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Your loop is happening once every frame. You need some event to make it happen only once. As oosyrag already stated, a mouse click, keyboard key pressed, or a button press.

    Just FYI, floor(random(9)) will actually give you values between 0 - 8. Here's a quote from the manual regarding the Random system expression, "Generate a random float from 0 to x, not including x"

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