How do I pick the next highest instance UID of a sprite?

0 favourites
  • 12 posts
From the Asset Store
Act on your instances, get/set their properties and variables only thanks to their UID. No more picking trouble! Plugin
  • Say there is a trail of sprites. Your monster comes across the trail and overlaps/collides with one. You want to be able to figure out what the UID of the next (more recent) sprite in the trail is so the monster can move toward that one (following a trail of breadcrumbs, so to speak). We can't use IID, because our trail is also disappearing, oldest instances first, which makes the IID's of the remaining sprites change constantly.

    What's is the best way to solve this?

  • UID probably would work. Or, to be in complete control, just add your own ID that increments each time. Then when you 'overlap' one, add one to the ID, Pick all, then pick by the new ID to get the next one.

  • Uid doesn't guarantee that a higher number will be an instance of that sprite.

    It could be another sprite, or a text object for that matter.

    IID can get you the most recent instance by using sprite(sprite.count).

  • You might be able to achieve what you want with something like this.

  • Newt is right about UID. My bad. Here's a sample with a dedicated ID.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • A higher UID always mean a more recent instance, so ordering by UID to do the picking could work. But it's so much easier to go with sprite(sprite.count - 1) that there's no reason not to !

  • That only works if the monster only overlaps the last item. It doesn't deal with the monster coming across any of the breadcrumbs and needing to follow from that location.

  • Oh, I did not fully understand the problem to begin with. To do that with the UID you'd have to loop through the UID ordered collection of your sprites and pick the first higher one... definitely not the way to go.

  • Aren't the iids reused?

  • Why not use a custom ID as someone already suggested?

    You have a variable "Breadcrumb_index = 0" or whatever

    Every time you create a breadcrumb you set its breadcrumb_index to this value and increase the variable by 1 which will be the index of the next breadcrumb and so on.

    Then in your overlap event you add:

    Monster is overlapping breadcrumb

    -----> Destroy breadcrumb

    Pick Breadcrumb with lowest Breadcrumb_index (Since this has to be the next in line)

    ------> Monster go to breadcrumb

    So even if they slowly go away, assume that those made first disappear first, then logically the next breadcrumb that the monster should go to will always be the one with the lowest Breadcrumb_index?

    Or wouldn't that work?

  • I've already provided that sample CAPX.

  • blackhornet and nimos100

    Yes, the custom id is a good solution, I don't understand why I didn't think of it before! Thank you! Simple and easy to implement.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)