Array question

Get help using Construct 2

Post » Tue May 28, 2013 3:19 am

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?

B
16
S
4
Posts: 24
Reputation: 1,009

Post » Tue May 28, 2013 3:43 am

[QUOTE=pseudotropheus] 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?

[/QUOTE]

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.
Everybody got to come out of the closet... does that mean I'm allowed to come out of the corner? Is that even funny anymore? Do parents still make their kids stand in corners when they mouth off?? These are the questions that keep me out of the really good schools.

havenisle.net
B
12
S
3
G
3
Posts: 27
Reputation: 2,740

Post » Tue May 28, 2013 3:49 am

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
B
16
S
4
Posts: 24
Reputation: 1,009

Post » Tue May 28, 2013 3:52 am



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.ArcadEd2013-05-28 03:55:25
B
101
S
32
G
11
Posts: 1,546
Reputation: 21,727

Post » Tue May 28, 2013 8:06 am

Thanks!
B
16
S
4
Posts: 24
Reputation: 1,009


Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 17 guests