# Checking if a value of a Ds_list repeats in another Ds_list

G

#### Guayuu

##### Guest
I'm not really sure if this is the most efficient way to check with every value of a Ds_list, if its value repeats in another Ds_list, but its just the way i came with (which isnt managing to work anyways), so i came here for some help to do some changes....

I have two objects, which IDs are in the b and c variables of a third object.
the third object which is supposed to check if the b and c objects are collitioning with this third object (itself)
To this point the code works right perfectly.
If there is collision, then this third object checks a DS_LIST called ancestry in object b and c (both ds_lists have only 6 positions, yes from 0 to 5), and checks with every value in b.ancestry if it repeats at least once in some position of c.ancestry, if it does repeat and isnt = "nothing", it sums +1 to the f variable.
So if the f variable equals 0, the code is supposed to create an instance. (Everything worked fine until i implemented the ds_lists checking thing, so im stuck in that)

i decided that when a value of the DS_LIST isnt a real number, in some code from the b or c it changes the value to the string "nothing", this isnt part of the problem, but i just tell you for the sake of explaining it all.

this is the code (in the Begin_step) that isnt working, it just does create the instance even if there is some value repeating in b.ancestry to c.ancestry:

Code:
``````f=0

var d;
for (d = 0; d < 6; d += 1)
{
var e;
for (e = 0; e < 6; e += 1 )
{ if ds_list_find_value(b.ancestry,e) = ds_list_find_value(c.ancestry,d)
{ if ds_list_find_value(b.ancestry,e) != "nothing"
{ f += 1}
}
}
}

if f=0 {instance_create_depth(x,y,0,o_fourthobject) }``````
Thank you guys....

Last edited by a moderator:

#### Vallo92

##### Member
Let me know if I understand what you want to do.
You have two lists present in two different objects. You need to check both lists. If the lists have no value in common (no equal value), then you create an object, otherwise nothing happens.
Did I get it right?

G

#### Guayuu

##### Guest
Let me know if I understand what you want to do.
You have two lists present in two different objects. You need to check both lists. If the lists have no value in common (no equal value), then you create an object, otherwise nothing happens.
Did I get it right?
that is exactly what i want to do.

#### Vallo92

##### Member
Ok, try this (sorry for the poor code, but im out of home and I write with my telephone):
Code:
``````var value, find;
find = false;
for(var i=0; i<ds_list_size(b.ancestry); i++) {
value = ds_list_find_value(b.ancestry, i);
for(var j=0; j<ds_list_size(c.ancestry); j++) {
if (value == ds_list_find_value(c.ancestry, j)) {
find = true;
}
if (find == true) {
break;
}
}
if (find == true) {
Instance_create......
}``````
Edit:
You could try toinsert the instance_create within the two checker's if. In this case you can remove the variable find, and its relative ifs.

G

#### Guayuu

##### Guest
Ok, try this (sorry for the poor code, but im out of home and I write with my telephone):
Code:
``````var value, find;
find = false;
for(var i=0; i<ds_list_size(b.ancestry); i++) {
value = ds_list_find_value(b.ancestry, i);
for(var j=0; j<ds_list_size(c.ancestry); j++) {
if (value == ds_list_find_value(c.ancestry, j)) {
find = true;
}
if (find == true) {
break;
}
}
if (find == true) {
Instance_create......
}``````
Edit:
You could try toinsert the instance_create within the two checker's if. In this case you can remove the variable find, and its relative ifs.
Thank you very much!, i tried your code but i didnt manage to make it stop creating the instance anyways... but then i realized that, actually my code did work, it was only that i also wanted it to don't create the instance if one of the values of the ds_list was equals to the ID of the second object having collision. but i didn't know that until i found out just by trying your code.

Thanks again.