DS Lists: find value and not position

hey all! In my game, enemies will respawn if you use a checkpoint.
Otherwise, enemies stay dead.

Initially, I was using persistent rooms, but decided to go another route because I like to have control over the things happening within my game.

Anyways, I decided to create a DS_list which contains a value unique to each enemy (I'm numbering each enemy in their create code starting with 0 and going up)

And when you use a checkpoint, the list is cleared and the enemies exit their death state and go back to being alive. Works great.

So when I load a room, each enemy runs a line of code using ds_list_find_index to see if their enemy number is in the list. If it is, they enter their death state upon loading the room. Otherwise, they remain alive.

This is done by creating a variable that = the return value of ds_list_find_index(death_list, enemy_num), which means the be enemy running the code is searching the list for their specific number

And then checking if that variable = the enemy_num of the enemy running the code

The problem is that it seems I have to kill them in order of their enemy number to make them stay dead.

It seems that ds_list_find_index finds the value AND position?
I don't want to find the position in the list, only the value. Because I don't want it to matter what order the player kills the enemies. How can I do this?
 
@Electros hmm.. Unless I'm mistaken, accessors access values in the list through position. That doesn't work. I don't want position in the list to be relevant at all.

I can't search through position because the position of the value in the list is never guaranteed. The player could run passed all the enemies and kill the last enemy first, making the last enemy the first in the list.

That's why I'm hoping to be able to find if the enemy number is anywhere in the list, regardless of position
 

GMWolf

aka fel666
@Electros hmm.. Unless I'm mistaken, accessors access values in the list through position. That doesn't work. I don't want position in the list to be relevant at all.

I can't search through position because the position of the value in the list is never guaranteed. The player could run passed all the enemies and kill the last enemy first, making the last enemy the first in the list.

That's why I'm hoping to be able to find if the enemy number is anywhere in the list, regardless of position
Ds_list_find_index will return -1 if the item is not in the list.
https://docs.yoyogames.com/source/d...a structures/ds lists/ds_list_find_index.html
 
@Tsa05 so, the problem with ds_list_find_value is that it's searching for the value through position within the list. As I've attempted to explain above, I can't search using position. Is there a way to find something within the list regardless of position within the list?
 
@Fel666 correct. Which is why I figured it would work, but it would seem that find_index searches through position. At least I'm pretty sure it does, because it only works correctly if my enemies were killed in order of their numerical value
 
It seems to me that ds_list_find_index returns the position within the list?

Correct me if I'm wrong:
Find_value is using the position in order to find the value and then find_index is using the value to find the position?

I don't want either of those.
I just simply want to be able to check a list for a value regardless of position, to be able to just ask "is this value somewhere in this list?" If yes, then remain dead. If no, then respawn

Hope this clarifies :)
 

GMWolf

aka fel666
It seems to me that ds_list_find_index returns the position within the list?

Correct me if I'm wrong:
Find_value is using the position in order to find the value and then find_index is using the value to find the position?

I don't want either of those.
I just simply want to be able to check a list for a value regardless of position, to be able to just ask "is this value somewhere in this list?" If yes, then remain dead. If no, then respawn

Hope this clarifies :)
again: If its not in the list, it will return -1.

So if ds_list_get_index returns anything else than -1, its in the list!
 
@Fel666 ahhhhhh!! I should have thought of that! Hahaha thank you so much for solving this and thanks to everyone else for dealing with my ignorance and obliviousness
 
Top