actions involving UID

This forum is currently in read-only mode.
From the Asset Store
Alot of High Quality Items sound effects for your game!
  • 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?

  • 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 <img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" />

    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).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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. <img src="{SMILIES_PATH}/icon_razz.gif" alt=":P" title="Razz" />

  • 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 <img src="{SMILIES_PATH}/icon_confused.gif" alt=":?" title="Confused" />

  • This way you can do a loop numOfObjects times, and use a condition of "loopIndex = spreadValue" to manipulate an individual instance.

    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.

  • > This way you can do a loop numOfObjects times, and use a condition of "loopIndex = spreadValue" to manipulate an individual instance.


    The For each condition completely supersedes this.

    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 <img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarassed" />

    I'll have to play around with it now that I know what to expect.

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