How do I filter one array into another array?

Get help using Construct 2

Post » Wed Feb 10, 2016 11:03 pm

I have an array with a width of 440 and a height of 5. It looks like this:

    [score, text1, text2, category, id]
For my app I need to sort the array by score but also filter it by whichever category the user chooses. To accomplish this I created another array and set it to have the same dimensions. Then I iterate through the array that has my data and copy ONLY the rows that match the chosen category into the new array. That part works great.

Unfortunately, since both arrays have the same dimensions, my new filtered array isn't as big and so has a bunch of "0,0,0,0" lines at the end.

How do I fix this? I suppose I could set all the "0" scores to a really high number so they would get sorted to the bottom, but there has to be a more elegant solution. Can I search through and delete the "0,0,0,0" rows?

Not sure if it will be useful but here's a picture of my function:
NOTE: On 'Start of layout' I load all my data into "array2" and this function copies everything that matches category "x" into the original array ("array")

Image
B
11
S
3
Posts: 85
Reputation: 866

Post » Thu Feb 11, 2016 12:37 am

You can set your second array to Size(0,5,1) and then do a Push on X, then set your values. This will only push as many as you need.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Thu Feb 11, 2016 8:10 am

Thanks, blackhornet. I tried using push last night and failed. Came online to learn more and saw some posts that said its not really for multidimensional arrays, so I gave up on the idea. Will look at it some more tonight, but if anyone has any advice...
B
11
S
3
Posts: 85
Reputation: 866

Post » Thu Feb 11, 2016 2:48 pm

As long as you only Push on X, it works.
http://www.blackhornettechnologies.com/ ... ample.capx
Run this with the Debugger, and click on Array.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Fri Feb 12, 2016 9:16 am

Message: 99Instances2Go can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Now you stille have (probably) a sorting problem.
Sorting in 2D and 3D arrays can not work as you expect it to work.

Hope i give you ideas with this cap (avoiding a sort algoritme)
https://drive.google.com/open?id=0B1SSu ... ElHMHpIeVU

Greetings.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Feb 12, 2016 9:18 am

id=0B1SSuCVV8v74N0JEUElHMHpIeVU

(can not post links yet)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Feb 12, 2016 1:25 pm

Thanks 99instances2go, I appreciate the help -- but I've never had any issues sorting my array. I only need to sort by the "score" and it's as simple as "sort x". Works perfectly. :-)

Oh, and thanks for the help with "push", blackhornet. With your help I got my app working last night. It has taken me almost a month (for something I thought I could do in a weekend), but it's almost finished now.

Most of my Flashcard app was super simple to make using C2, but I struggled with array handling, loading/saving data, the dictionary object, and local storage. The next project should go a LOT smoother.
B
11
S
3
Posts: 85
Reputation: 866


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests