Picking adjanced instances of same object

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello,

    I've ran to a problem with picking instances. Here is quick description: I have three sprites next to each other, and I'd like to link them so that they each know each others UID. This is not the hard part, UID's set nicely as intended. Problem is that when I try to access the another sprite in the events, something fails. This is probably syntax thing or something even more obvious that I am missing, here is pseudo code of what I am doing.

    For Each Sprite:

    set LocalVariable = Sprite.UID

    pick nearest sprite at x,y

    set LeftSpriteUID = LocalVariable

    It seems that pick nearest sprite at x,y fails. X and Y are defined so they are a bit left of the original sprites left border and definitively inside another sprite. If I add 'dont pick yourself' condition to the pick nearest condition, nothing is returned.

    If someone can shed me some light on where I am thinking wrong here I'd appreciate! :)

  • I think this is an issue of updating the "SOL". If I am right they are all instances of a single sprite.

    In short when you are using a For each a single sprite is selected and the rest of the code will be using only that instance of the sprite. To overcome this you add a system event "Pick all". I just helped solve one such issue take a look:

    http://www.scirra.com/forum/isolate-identical-sprites-by-variables-for-testing_topic50378_post317619.html?KW=#317619

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you very much, that was the problem! :)

    Here is another question I've been wondering about instancing that seems a bit odd to me. Rather than starting a new thread about it I tought I'd put it here as it is very much instancing related thought error from my part as well.

    I have sprite with variable FindPath(boolean)

    I have event that says: FindPath=True : Do stuff to find my path

    The idea here is that when the sprite needs to find a way to get from point A to point B, it sets FindPath to true. And it seems to work as intended, until I have multiple instances of that same sprite all kinds of odd things start happening. So always suspectfull about instancing mechanics I print the sprite.uid to my debug box every time FindPath is set to true and behold, the sprite.uid inside FindPath functionality always printed "0". I imagined the sprites instance would be passed on to the FindPath=true function, but I guess this is the wrong way of thinking?

    What I am trying to achieve here is sort of traditional 'function call' mechanic, which would be the best way to do it in construct 2?

  • You are right that the properties of the instance will be passed to your function. But for some reason it seems that always the first instance is picked. Can you provide the .capx!

  • You were correct again, the problem was actually classical: error in my debug text :)

    Thanks!

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