Using Family to choose: How to check if an object exists?

For questions about using Classic.

Post » Thu Nov 11, 2010 7:29 am

I have a sprite which has a private variable that functions like UID (although not exactly the same purpose as UID), and I regularly use For Each Object (ordered) to loop through the instances of this sprite using this private variable. Instances of this sprite regularly get destroyed and created throughout the course of the game, and the private variable is unique for each instance upon creation of the instance.

For any given sprite instance with a given private variable, I want to pick another sprite instance (using Families, since this sprite is in a Family) that has the next highest (or lowest) value of this private variable. And I can't assume that the next highest or lowest is just +1 or -1 away, since the sprite instances with these values may have been destroyed.

In short, how do you check if a sprite you are picking using Families exists or not? I need to know this, so that if it doesn't exist, I can keep searching for the next one.
Posts: 59
Reputation: 993

Post » Thu Nov 11, 2010 4:15 pm

Why not just keep the next and previous values +1 and -1 away. When you destroy an object pick all the objects with greater values than the one being destroyed and subtract 1 from each. That will creating gaps.
Posts: 4,663
Reputation: 37,191

Post » Thu Nov 11, 2010 5:21 pm

Well, it won't be picked if it doesn't exist
There is a "for each object ordered" where you could loop through them in order of the private variable
If for whatever reason that won't work in a subevent of a "for each object" loop
-family name is equal to (the number you're checking against)

Then it will loop through each objectr but only go into those actions if the object also contains. The correct value
Spriter Dev
Posts: 3,231
Reputation: 16,293

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests