multiple results in array search

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • According to the manual :

    IndexOf, LastIndexOf

    Searches the array X axis for a given value and returns the index it is found at, or -1 if not found. IndexOf finds the first matching element, and LastIndexOf finds the last matching element.

    I successfully use it.

    But I need to find all matching element in a search (more than 2).

    How to do that?

    I thought of i= array.indexOf(searchstring)+1, compare value until i=array.lastindexOf(searchstring) but I wonder if there's a way to use index and not while loops?

    For example, can we re-search index starting at lastresult+1?

    I know it might look weird but my array is 1942 long <img src="smileys/smiley36.gif" border="0" align="middle" />

    So far I didn't find that entries are limited which is a very good thing.

    I wonder what happens to the browser (or smartphone app) if "you go too far" and how much is "too far".

    Thanks for your help!

  • In the Array Plugin, both IndexOf and LastIndexOf take only 1 argument : the value to search for, and I'm sorry to say there isn't, in the official implementation, a way to get the result of a search starting from the Nth index.

    Anyhow, if you don't know how many items will have the searched value, there is no use of having a list of all the index. Why ? Because to use them, you would have to do a forEach on the list/array. Why not just do a simple forEach on the first array, and do the full iteration only when the value matches what you are looking for ?

    Regarding the "too far" consideration, just know that C2 Arrays use javascript arrays to stock datas. Having a big array isn't a problem, as long as the total sum of the datas weight isn't excessive. Having 5k names isn't a problem. Having the base64 code of 100 pictures is. It all depends on how much data is in the array. Arrays are optimised since V8 for very fast access and writing, so lots of elements don't seem to be so problematic now. (more on this here)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Guizmus,

    Hmm, right, I'll need to improve my search logic because one argument can be found multiple times in index.

    My json file is 258k and it's pretty fast on the laptop but I wonder on a mobile device and if it's RAM related too (?).

    I also wonder if there's a limit per dimension (x,y,z).

    I thought of using long strings or integers to concatenate and do layer search but then I wonder how many digits it can handle before going to lala land and if it's also CPU (mobile battery) intensive.

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