Function for several elements

Get help using Construct 2

Post » Wed Jan 18, 2017 3:05 pm

I am wondering if there is a way to create a function that will do something for different elements.

Here is what I mean:
I have several droppables (drag1 to drag6) that I want to go to a certain position when they are dropped. They first overlap an image (either one of d1 to d6) and then they are placed under the proper image.
Right now it works but I basically have to repeat for each draggable:
Code: Select all
if drag1 is overlapping d1 then set drag1 position to d1.X and 202
if drag1 is overlapping d2 then set drag1 position to d2.X and 202
if drag1 is overlapping d3 then set drag1 position to d3.X and 202
if drag1 is overlapping d4 then set drag1 position to d4.X and 335
if drag1 is overlapping d5 then set drag1 position to d5.X and 335
if drag1 is overlapping d6 then set drag1 position to d6.X and 335


Then I have to do this for drag2 to drag6.

This seems so redundant.
B
8
S
1
Posts: 86
Reputation: 618

Post » Thu Jan 19, 2017 11:18 am

I cant not stress this enough. Although i have not the autority to do so.
Your events are redundant because you dont use instances, and you dont know how to pick them.

It is as easy as this:
https://drive.google.com/open?id=0B1SSu ... lRZLUFWVmc

At the same time i show you a proper use of a function.
A function is needed when you have to pick from scratch. And i need to, because the 'on drop' picks only 1 sprite2, while i need to evaluate the others too. So, i have to broaden the picklist. (can also with 'pick all')
A function is convenient if it is a block of events that can be reused with other parameters, when the function can pick the right instance or the right member of a family. In other cases you only dive deeper into problems because the set up is to complicated, especially when using a new object for each sprite.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, trance, yiuyiu6666 and 5 guests