How do I search through an array??

Get help using Construct 2

Post » Sat May 30, 2015 7:46 am

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"
Image

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

thanks in advance!
B
7
S
1
Posts: 28
Reputation: 481

Post » Sat May 30, 2015 11:02 pm

c'mon guys i do really need your help!
B
7
S
1
Posts: 28
Reputation: 481

Post » Sat May 30, 2015 11:11 pm

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.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Sun May 31, 2015 12:00 am

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
B
7
S
1
Posts: 28
Reputation: 481

Post » Sun May 31, 2015 12:13 am

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
B
66
S
24
G
7
Posts: 1,513
Reputation: 11,037

Post » Sun May 31, 2015 7:55 am

im not able to openit, because its on a newer version than mine xD
any images?
any simple explanation?
B
7
S
1
Posts: 28
Reputation: 481

Post » Sun May 31, 2015 5:26 pm

ok...let's say....you have 3 arrays

ArrayGirls (4,1,1)
Image
Code: Select all
"{""c2array"":true,""size"":[4,1,1],""data"":[[[""ana""]],[[""christine""]],[[""valentine""]],[[""charlotte""]]]}"

ArrayBoys (4,1,1)
Image
Code: Select all
"{""c2array"":true,""size"":[4,1,1],""data"":[[[""john""]],[[""mike""]],[[""martin""]],[[""josh""]]]}"

ArrayEmotions (4,4,1)
Image
Code: Select all
"{""c2array"":true,""size"":[4,4,1],""data"":[[[""love""],[""love""],[""hate""],[""hate""]],[[""hate""],[""friends""],[""friends""],[""friends""]],[[""friends""],[""friends""],[""love""],[""crush""]],[[""crush""],[""meh...""],[""hate""],[""crush""]]]}"


......... What Josh feels for Ana?

...lets say .Boys are X...and Girls are Y
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> http://s000.tinyupload.com/index.php?fi ... 9119336807
(r200)
Last edited by korbaach on Mon Jun 01, 2015 2:36 am, edited 1 time in total.
B
66
S
24
G
7
Posts: 1,513
Reputation: 11,037

Post » Mon Jun 01, 2015 12:19 am

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)
B
7
S
1
Posts: 28
Reputation: 481

Post » Mon Jun 01, 2015 2:35 am

...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
Image

BoysSprite
Image

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"

Image

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

etc....
B
66
S
24
G
7
Posts: 1,513
Reputation: 11,037

Post » Mon Jun 01, 2015 9:09 pm

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

Image
B
7
S
1
Posts: 28
Reputation: 481


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests