Function for several elements

0 favourites
  • 2 posts
From the Asset Store
Several elements of the game interface hidden objects
  • 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:

    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
    [/code:j876r2cs]
    
    Then I have to do this for drag2 to drag6.
    
    This seems so redundant.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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