Pick instances by instance variable within an expression?

Get help using Construct 2

Post » Thu Jan 12, 2017 2:23 pm

As above

Is it possible to pick object instances based on an instance variable directly within an expression?

For example
If I have 5 point sprites P, each with an instance variable “ID” = (A) to (E) .
And I want to draw a line between only 2 of the points, say P(ID=B) and P(ID=E).

Then is there any way to pick them directly in an expression?
Specifically thinking, passing function parameters in a function call?

eg in semi-psudocode.... just calling a function passing the X and Y values of P(ID(B)) and P(ID(E))

On button click - call function (“drawlinebetween”) (Parameter(0)= Sprite P(with instance variable (“ID”=B).X), Parameter(1)= Sprite P(with instance variable (“ID”=B).Y), Parameter(2) = Sprite P(with instance variable (“ID”=(E).X, Parameter(2) = Sprite P(with instance variable (“ID”=(E).Y ).

On function “drawlinebetween” - [draw line between points XY1 and XY2] (function.Para(0) , function.Para(1), function.Para(2), function.Para(3) )


?cheers?
...
B
47
S
25
G
7
Posts: 365
Reputation: 8,436

Post » Fri Jan 13, 2017 2:14 am

Try it!

If you run into any issues, we'll help you fix it! :)
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Fri Jan 13, 2017 2:21 am

There's a system condition called "pick by evaluate." You can choose the object type you want to pick by clicking it in the window that pops up, then use an expression like "object.variable = 1"
Eh, Steve!
B
115
S
54
G
13
Posts: 113
Reputation: 16,151

Post » Fri Jan 13, 2017 5:42 am

You can access other instances by iid with sprite(i).x, where i is an instance number. I guess you could make a helper function to pick the instance by a variable and return the iid. I'd just change your drawl one function to take the variable values and do the picking inside the function.
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Fri Jan 13, 2017 9:57 am

@spacedoubt
thanks I did try it but I couldnt see a way of doing it directly with construct 2 built in features hence the pseudocode

@calebbennetts
yes, currently I am solving the issue by picking instances before feeding them to the function but it will prove very ineficient for large amounts of sprites and you cant use this pick by evaluate within an expression hence the question.

@R0J0hound

Dude , youre a genius. Why didnt I think of this?


I feel a bit dumb now......(especially as I was talking about functions. See Im starting to understand this construct 2 stuff but im still not thinking like a coder)


Thankyou very much


I will try it this weekend and post a capx so people get what I was on about
...
B
47
S
25
G
7
Posts: 365
Reputation: 8,436

Post » Sat Jan 14, 2017 1:07 am

so I tried it out on something "simple" (haha) for this question

how-do-i-create-a-world-of-goo-mouse-effect_t186307?start=10

and it worked. thanks again @R0J0hound

for anyone that interested theres a capx in my arcade link t(the second one "GooTwo") in the above thread.

or straight here https://www.scirra.com/arcade/other-games/goo-two-14408

you will see that the drawline function passes parameters that are themselves calling function getIDfromUID to get the index number of the sprite from the UID (which could be swapped for an IV) , hope that makes sense

anyway.

stamping as solved...... (how to I change the heading to marked solved ????)
...
B
47
S
25
G
7
Posts: 365
Reputation: 8,436


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests