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

Get help using Construct 2

Post » Fri Apr 04, 2014 1:56 pm

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?
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Fri Apr 04, 2014 2:47 pm

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.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Fri Apr 04, 2014 3:14 pm

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).
Image ImageImage
B
169
S
50
G
174
Posts: 8,328
Reputation: 110,800

Post » Fri Apr 04, 2014 3:45 pm

You might be able to achieve what you want with something like this.
You do not have the required permissions to view the files attached to this post.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Fri Apr 04, 2014 5:02 pm

Newt is right about UID. My bad. Here's a sample with a dedicated ID.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Fri Apr 04, 2014 5:35 pm

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 !
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Fri Apr 04, 2014 5:44 pm

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.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Fri Apr 04, 2014 5:54 pm

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.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Fri Apr 04, 2014 6:04 pm

Aren't the iids reused?
Image ImageImage
B
169
S
50
G
174
Posts: 8,328
Reputation: 110,800

Post » Fri Apr 04, 2014 6:04 pm

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?
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Next

Return to How do I....?

Who is online

Users browsing this forum: Fradno, MathNook and 37 guests