How to parse elements in an array

Get help using Construct 2

Post » Mon Jan 13, 2014 9:19 am

Hi,

I have a sequence of numbers stored in an array as single numbers for each element. I'm trying to search for consecutive number of matches. Example:
1 2 3 3 3 2 2 3 3 2 2 2 1 1 1 1

The result would be:
three 3s
two 2s
two 3s
three 2s
four 1s

Also, the sequence of numbers can have varying lengths.

I've tried using WHILE but to no avail as the condition to stop the WHILE loop doesn't seem to work:

WHILE
array.at(index) NOT EQUAL TO 0 (action)

In the action, I increment index.
I'm trying to check for matches while not end of sequence taking 0 to be the end of the sequence. By the way, if the array element is empty,is it still a '0' or a NULL?

Any help rendered will be greatly appreciated.
B
11
S
2
Posts: 11
Reputation: 1,247

Post » Mon Jan 13, 2014 9:39 am

I'm still learning about arrays myself, but I tend to use these kind of conditions:

array - for each xy
system compare : array.curY is 0
system compare : array.curvalue is not 0
- set array2.At(array.curX,array.curY) : 25*Array.curvalue
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jan 13, 2014 10:59 am

I would go with something like

array count

BUT

this is rougher than I feel after a night out and this is not finished - it needs to checks the last number sent - probably the cheapest way would be to force a number at the end that is never going to normally be there...(which I have done here in a very elegant way )

I expect there is a much better way - but its a start if no one else comes along...

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Jan 13, 2014 1:55 pm

Actually what I need to know is how do you compare two consecutive elements in an array?
B
11
S
2
Posts: 11
Reputation: 1,247

Post » Mon Jan 13, 2014 2:21 pm

something like (not tested)

system compare two values

array.curvalue (comparison) array.at.array(currentX+1) ?

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Jan 13, 2014 2:43 pm

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Jan 13, 2014 2:52 pm

It is rather simple:
https://copy.com/OqrKHoesNdWpheF8
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Mon Jan 13, 2014 3:44 pm

Thanks a lot guys. You have been a great help.
B
11
S
2
Posts: 11
Reputation: 1,247


Return to How do I....?

Who is online

Users browsing this forum: dop2000, LunaticCat, matriax and 8 guests