actions involving UID

For questions about using Classic.

Post » Sun Dec 16, 2007 7:38 pm

i know construct keeps track of unique ids but how would i go about performing an action on a specific sprite with a specific uid?

i know one possibility is to single it out in the conditions but what if i have the conditions check one sprite with, say, id 1 but the actions will affect sprite with id 2?
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Sun Dec 16, 2007 8:00 pm

You can do this with the function object. Call a function, eg. "DoStuff" and forget picked objects. Then add an event like:

+ On function "DoStuff"
+ Sprite UID is 2
: Sprite: do something...

Because the picked objects are wiped clean for the function call, you can then pick the sprite with the UID you want from a clean slate and do something with it. Remember, after the function call the picked objects from the old event are restored :)

If the object of the UID you want to specifically modify is already picked, you can add a subevent 'Sprite UID = 2' and do something with it there. It will then pick the sprite with UID 2 so long as it was picked in the parent event.

Out of curiosity, why do you need actions on specific instances? Just wondering the circumstances, in case we can better design a solution (or if one already exists).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Dec 16, 2007 9:11 pm

ohhhh right, right, the conditions pick the sprite for the intended actions. i guess it took my brain a while to process the complex parts that the simpler parts didn't process at all! XD

anyways, the reason i ask is because i'm playing around with some manually implemented physics so that it affects all sprites, as well as for AI purposes. like a loop for movement but the loop can be triggered either by player input or by a triggered event at runtime but the loop will apply to anything depending on the uid that's picked.

maybe there's a better way to achieve this but this is how my brain is thinking at the moment. :P
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Mon Dec 17, 2007 9:20 am

Affecting specific instances is useful when you have complicated, automated routines for multiple instances of things (like a gravity routine that affects every enemy). You can do it in MMF by using Spread Value, which is sort of like assigning your own UID's. But with Spread Value you have the advantage of knowing that the UID's go exactly in order from 0 to numOfObjects. This way you can do a loop numOfObjects times, and use a condition of "loopIndex = spreadValue" to manipulate an individual instance. I've actually been trying to come up with a way to do something similar to Spread Values in Construct, because I use them so much in MMF.

For instance, I made a pachinko-type screen saver in Construct a while back, where physics balls randomly drop through a series of pegs. Occasionally one of the balls would get stuck on a peg, so I made a routine that would "bounce" the screen and set that ball's velocity to something random so that it would shake loose of the peg. But when it triggered, every ball on the screen was affected, whether it was stuck or not.

With Spread Values I could have fixed that problem very easily, and I guess if I knew what I was doing with UID's, I might be able to fix it that way as well, but I don't :?
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Dec 17, 2007 4:48 pm

[quote="deadeye":2bb7t9h5]This way you can do a loop numOfObjects times, and use a condition of "loopIndex = spreadValue" to manipulate an individual instance.[/quote:2bb7t9h5]

The For each condition completely supersedes this. It automatically triggers for each instance - or each picked instance, if more picking conditions are above it - and allows you to perform actions on instances individually. You can even for-each two objects in one event, and use a Compare Values to compare distances or whatever, to cycle all combinations of instances (the Turret movement is probably better at this though). So "Spread value" is completely redundant in Construct.

I'd be interested to see a .cap or some events demonstrating a situation where specific instance manipulation by UID is the only solution, and no better way exists. I only really put in UIDs to allow for referring to a specific object over time.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Dec 17, 2007 9:03 pm

[quote="Ashley":2i8idg2d][quote="deadeye":2i8idg2d]This way you can do a loop numOfObjects times, and use a condition of "loopIndex = spreadValue" to manipulate an individual instance.[/quote:2i8idg2d]

The For each condition completely supersedes this.[/quote:2i8idg2d]

Ah, I see now... I was under the impression that a "For each" loop was just a shortcut way of doing a For loop numOfObjects times. I feel a bit stupid :oops:

I'll have to play around with it now that I know what to expect.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests