how do I get an object by its variables?

0 favourites
  • 5 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • I was looking into arrays, so I created a 2d array, looping it to draw a grid of "Cube" sprites.

    Each cube has an X and a Y variables to state their position inside the array.

    When clicking on a cube, I want to check the cube near it (X+1, or Y-1 etc...)

    Is there a "Cube[X-1 && Y-1]" way to get it?

    Transition from real coding to event sheet really confuses me :/


  • You can pick an object based on its variable quite simply. Just use conditions "MyObject : compare instance variable", multiple ones in the same event, to "filter" every of the MyObjects to just keep the one that validate every conditions (if none validate everything, the events won't be run).

    Or... If you come from "real coding", go for functions then

    You can do a function "checkCube", waiting for 2 parameters (X and Y).

    Functions in C2 work in different ways :

    • you can have as many parameters as you like
    • a function can use "pause" instruction, but will loose its context (and parameters)
    • a function can act (meaning it can use actions and influence the game like any other events)
    • a function can also be called "inline", in witch case it will be "evaluated" and the return value will be used where you called the function.
    • a function can set a return value.

    Here are some examples I made, and the manual

  • You use the For Each [cube] condition and check if the values of the x ans y variables match your criteria

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Guizmus' suggestion is more direct: ... Cubes.capx

  • Ahhh this is great stuff! With functions, I feel at home

    Mission accomplished with ease

    Thank you very much, everyone!

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