Pick (nearest) instance in expression

Get help using Construct 2

Post » Mon Mar 05, 2012 3:41 pm

Hi folks,

I have a layout with many small objects. All of them are constantly moving to the left and when one of them leaves the layout to the left, I send them to the right of the layout.
My problem now is, that I want the instance that I send to the right to have its values like size changed corresponding to the values of the instance just left to it.
Does anyone understand what I mean? ^^
I have this acquired with an expression like this:
"Set height to: Object(Object.Count-1).Height"
But the problem is that I have two rows of the objects, one at the top of the layout and one at the bottom and each should react on its own.
So in conclusion my question is whether it is possible to pick the nearest instance of an object in an expression. I know there is the condition for this, but I need it in an expression.
B
10
S
1
Posts: 15
Reputation: 849

Post » Tue Mar 06, 2012 2:06 am

Perhaps this would work?

localvalue TempUID
Pick nearest --> set TempUID to object.UID

Then use TempUID in the expression?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Mar 07, 2012 12:02 pm

Could you please explain furter what you mean with that?
B
10
S
1
Posts: 15
Reputation: 849

Post » Wed Mar 07, 2012 1:27 pm

Use the common condition "Pick nearest".
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Wed Mar 07, 2012 1:32 pm

I tried that, but I need to pick the nearest not in the condition but in the expression...
B
10
S
1
Posts: 15
Reputation: 849

Post » Wed Mar 07, 2012 1:40 pm

Then you could try and use distance(x1,y1,x2,y2).
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Wed Mar 07, 2012 1:54 pm

This checks the distance between to points? But I want to know which of the instances the nearest is. For this function I already need the points of the instance, don't I?
B
10
S
1
Posts: 15
Reputation: 849

Post » Wed Mar 07, 2012 1:58 pm

Yeah, you would need a loop, or a for each.
In any case, the condition is a better choice.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Wed Mar 07, 2012 2:02 pm

For now I have changed the layout to have just one row of the instances at the top and a second one at the bottom but these are a different object. So I can handle them seperatly. Works for this, although I have to double every action for them. I am really missing an OR in conditions...
B
10
S
1
Posts: 15
Reputation: 849

Post » Wed Mar 07, 2012 5:16 pm

I'have similar issue for instances of the same object, something like
Sprite: Pos = "exit" -> Sprite: Set Y to Sprite.Pos("enter") could be nice ;)
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Next

Return to How do I....?

Who is online

Users browsing this forum: WhosWho and 18 guests