How do I search through an array??

0 favourites
  • 10 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Ok, i've looked using the search tool and i think i didnt found anything similar, but how i can search for a combination in an aray

    for example

    xxxxxxxx |john| |mike| |martin| |josh|

    ana-------- |love| | hate | |friends| | crush|

    christine |love| |friends | |firends| |meh...|

    valentine |hate| |firends| | love| |hate|

    charlotte |hate| |friends| |crush |crush|

    so, in this example (do not judge anyone feelings or behaviours) how can i look what valentine feels for martin?

    or what josh feels for ana?

    i hope you can help me because C2 said no programing required, but they didnt said that you still need everything else xDD

    byt the way, lets look at this "array"

    if instead of numbers i have another values, how can i find out the result of the column and row?

    thanks in advance!

  • c'mon guys i do really need your help!

  • Well, the problem is that indexOf and lastIndexOf only work on single rows. You could scan through with a loop, but my preferred solution would be to have a key.

    e.g. suppose you have an array 3x2 or more

    Joe, Smith, ...

    Fred,Bloggs, ...

    Jane,Jones, ...

    Now create another array which is a combination of those e.g. a 3 x 1 array, by concatenating the two parts with a semicolon and making it all lower case.

    joe;smith

    fred;bloggs

    jane;jones

    then if you want to search on a pair, you can look for jane;jones in the key array and the index returned by indexOf should be the same as that in the 3x2 array. You have to be careful that if you manipulate the data array, you synchronise the key array with it. Partly how you do this depends how much your data changes.

    This is (incidentally) how you used to do database systems before SQL became popular in the 1990s.

  • mmm... that means that i have to create many 3*1 arrays or dictionary?

    there is no another way? BTW setting your examples to match with my examples could be less confusing xDD

    thx anyway

  • max 3 arrays...BoysName_Array...GirlsName_Array...and..Emotions_Array

    quick example... two Lists & one Array

    capx> http://s000.tinyupload.com/index.php?fi ... 8769484996

  • im not able to openit, because its on a newer version than mine xD

    any images?

    any simple explanation?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ok...let's say....you have 3 arrays

    ArrayGirls (4,1,1)

    "{""c2array"":true,""size"":[4,1,1],""data"":[[[""ana""]],[[""christine""]],[[""valentine""]],[[""charlotte""]]]}"[/code:ug9tqoue]
    [b]ArrayBoys[/b] (4,1,1)
    [img="http://i58.tinypic.com/14c9ovn.png"]
    [code:ug9tqoue]"{""c2array"":true,""size"":[4,1,1],""data"":[[[""john""]],[[""mike""]],[[""martin""]],[[""josh""]]]}"[/code:ug9tqoue]
    [b]ArrayEmotions[/b] (4,4,1)
    [img="http://i58.tinypic.com/33nxg07.png"]
    [code:ug9tqoue]"{""c2array"":true,""size"":[4,4,1],""data"":[[[""love""],[""love""],[""hate""],[""hate""]],[[""hate""],[""friends""],[""friends""],[""friends""]],[[""friends""],[""friends""],[""love""],[""crush""]],[[""crush""],[""meh...""],[""hate""],[""crush""]]]}"[/code:ug9tqoue]
    
    .........[b] What Josh feels for Ana?[/b]
    
    ...lets say .[b]Boys are X...and Girls are Y[/b]
    so..joshX=3;....and...AnaY=0.......ArrrayEmotion at (3,0)= "Crush"
    or
    ArrayEmotions.At(ArrayBoys.IndexOf("Josh"),ArrayGirls.IndexOf("Ana"))= "Crush"
    
    ...........................................................................................................................................................................
    ...you really need to update  C2...or learn how to revert capx to an earlier version of Construct 2...
    ............................................................................................................................................................................
    
    capx> [url=http://s000.tinyupload.com/index.php?file_id=98081279039119336807]http://s000.tinyupload.com/index.php?fi ... 9119336807[/url]
    (r200)
  • ok i think i've got it, so that means that instead of strings i can also use values stored in variables right? i just have to remove the "'s

    that also means that i dont have to make 3 arrays, just to give a instance variable with the order number for each one (in case that i made an object of those names or objects and so)

  • ...you just have to determine x and y for ArrayEmotions

    you can use arrays,global variables,instance variables,list, animaton frames..

    let's say you have two sprites..4 frames each

    GirlsSprite

    BoysSprite

    now you may request value:::

    ArrayEmotions.At(BoysSprite.AnimationFrame,GirlsSprite.AnimationFrame)

    ........................................................................................................................................

    if you using arrays you can store all data(instance variable)..not just "name"

    set "name"...ArrayBoys.At(BoysSprite.AnimationFrame)

    set "age"....ArrayBoys.At(BoysSprite.AnimationFrame,1)

    etc....

  • alright!

    thanks so much, dude, you deserve a big, big cookie!

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