Array question

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • If I have an array full of 1's and 2's, and I want to count how many 1's are in the array, how do I do it?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If I have an array full of 1's and 2's, and I want to count how many 1's are in the array, how do I do it?

    How big is your array?

    If you're trying to discover the contents, I would suggest building a debugger. That way, while you're in-game, you'll always know the content of your array.

    I don't know the best way, but you could try something like "Every Tick, set TEXT to Array.curValue" I'm a newb myself, but that might help. Maybe do a textbox that constantly updates?

    Maybe do a for each? How, I'm not sure. I usually just play around until it works.

  • The array will typically contain under 100 values.

    I do have "Every tick, set text to "Array.ASJSON" which does display the contents, I was just hoping for a more elegant way to display these data.

    Like Soldiers: 1 Monsters: 5

  • <img src="http://content.screencast.com/users/ArcadEd/folders/Jing/media/bff0c44f-5e9d-4275-8928-51171498acf8/2013-05-27_1952.png" border="0" />

    CountOnes is a global variable.

    I just used the touch event to trigger the for each event, obviously you would use something different.

    You can also just change the current value to 2 to count up the 2s.

  • Thanks!

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