GameMaker how to compare object to a ds list index?

lamatoast

Member
Hi guys, when i click on and object i want to compare it to a ds list, this is how i do it but it throws an error.

Code:
if object_index == ds_list_find_value(grid,0)
{
    instance_destroy();
}
 

O.Stogden

Member
What error are you getting?

Perhaps "grid" isn't a global variable, at a guess. And can't be referenced by the object running the code.

And if there's several instance of that object, it might be best to store the "id" rather than the "object_index".
 

lamatoast

Member
Thanks 0.Stogden making the variable global fixed the the issue. for some reason i thought ds lists where global automatically.
 

samspade

Member
Lists are 'global' in the sense that if you have their reference any object can reference them. However, the variables that hold the reference follow all normal scope rules. So A and B can both reference the list but if A has an instance variable holding a reference to the list B can't use A's variable. It needs its own or the reference needs to be stored in a global variable.
 
Top