Picking adjanced instances of same object

Get help using Construct 2

Post » Sun Apr 15, 2012 7:54 pm

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! :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Sun Apr 15, 2012 8:21 pm

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
B
28
S
9
G
6
Posts: 30
Reputation: 6,609

Post » Mon Apr 16, 2012 10:30 am

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?
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Mon Apr 16, 2012 4:37 pm

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!
B
28
S
9
G
6
Posts: 30
Reputation: 6,609

Post » Tue Apr 17, 2012 9:15 am

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

Thanks!
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider] and 12 guests