A problem with ds_list_find_index

Z

Zefyrinus

Guest
Hi! I'm having a lot of problems with ds_lists. Explaining my project and stuff would take ages, so I'm cutting right to the problem. In a for-loop I'm searching for given values in a ds_list (the first line in this code). The next two show_message lines tell me that in position 0 in this ds_list, the value 0 is indeed stored. But the last two lines show me that found_value = -1. That is to say, in the first line of this code, the value 0 doesn't get found in the ds_list pref_movement, even though I know for a fact that it's at least stored in pref_movement[0]. Can anyone figure out what's going on? :confused:
Code:
found_value = ds_list_find_index(pref_movement, i);
show_message("pref_movement[0] is:");
show_message(string(ds_list_find_value(pref_movement,0)));
show_message("found_value is:");
show_message(string(found_value));
EDIT: Oh, and I have GM 6.1. :oops:
 
Last edited by a moderator:
Z

Zefyrinus

Guest
So you are searching for the value of i in your list, correct?
If i is not set to 0, then you will get different results.
This is in a for-loop. It starts on 2 and goes down to 0. I've even tried replacing i with 0, but it still returns -1. And I have checked and made sure that the value 0 does get added to the ds_list. So it's really mysterious why it's not working. :/
 

TheouAegis

Member
So you're saying this code:
Code:
i = 0;
found_value = ds_list_find_index(pref_movement, i);
show_message("pref_movement[0] is:");
show_message(string(ds_list_find_value(pref_movement,0)));
show_message("found_value is:");
show_message(string(found_value));
Is returning this series of messages:

pref_movement[0] is
0
found_value is:
-1
Correct?

So, did you add 0 to the list or did you add "0" to the list? Double-check that you didn't accidentally put quote marks in your code. Also if you're reading from a file and storing the read data from the tile into the list, make sure you're reading the data as reals and not strings.
 
Z

Zefyrinus

Guest
Sorry for not replying in ages!

So you're saying this code:
Code:
i = 0;
found_value = ds_list_find_index(pref_movement, i);
show_message("pref_movement[0] is:");
show_message(string(ds_list_find_value(pref_movement,0)));
show_message("found_value is:");
show_message(string(found_value));
Is returning this series of messages:



Correct?

So, did you add 0 to the list or did you add "0" to the list? Double-check that you didn't accidentally put quote marks in your code. Also if you're reading from a file and storing the read data from the tile into the list, make sure you're reading the data as reals and not strings.
No, I did like this:
Code:
found_value = ds_list_find_index(pref_movement, 0);
show_message("pref_movement[0] is:");
show_message(string(ds_list_find_value(pref_movement,0)));
show_message("found_value is:");
show_message(string(found_value));
I'm not reading anything from files. When I run the game, it shows those messages you just wrote.
 

TheouAegis

Member
Post the code you used to create the list.

Make sure you actually assigned a value to index 0 in the list.
And again, make sure you actually put 0 and not "0" in the list.

As has been stated too, it's possible it's a bug in GM6, which is ridiculously old.
 
S

Salvakiya

Guest
not sure I understand... but I might understand the question... just to make sure we are on the same page the following is true:

list[|0] = 1
list[|1] = 123

ds_list_find_index(list, 1) = 0
ds_list_find_value(list, 1) = 123

i know you said you are using 6.1 so you dont have accessors but act like list[|X] is ds_list_add

find_index will find the INDEX which contains given value
find_value will find the VALUE at the given index
 
Z

Zefyrinus

Guest
Oh. My. God! >________________________________________< I found the problem. I thought I'd never solve it. It turns out that it's not enough to just use ds_list_create, if you're using ds_list_replace, like I had at some points, it doesn't work if no values have been added to the list to begin with. So in the creation event of this object, I added zeroes to pref_movemen[0]-[3], and after that everything worked. >__________< Thanks for taking your time trying to solve this everyone!
 
Top