Search for objects connection - Array

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hello.
    Is there an option to check if objects are connected together using array?
    If yes, how to do that?
    I want to make pipes, and if they are connected together and to point in 1 place on map it's changing theirs animations,value etc.
    I want to make something like furnance, and then to furnance connect pipes. If pipes are connected it's changing theirs animation on red

  • If your pipes are arranged in a grid, you can also layout your array in a grid with the x and y array dimensions mimicking the x and y axis of the grid. Then use values to determine what direction the pipes are oriented. For example, a value of 0 might mean the grid space is empty, a value of 1 could mean a horizontal pipe that connects to the spaces on the right and left. A value of 2 could be a vertical pipe. A value of 3 could be a bend. Etc. You will need to think about all pipe shapes you need.

    Then once you have all this laid out, you can set the animation based on the number in the array.

    Please login to see this link.

  • To be honest, I probably wouldn't even use an array for this.
    Make each pipe section an active object. Give them x_pos and y_pos alterable values, storing their grid positions. Give them four more alterable values, indicating whether or not they are able to connect on each of their four sides (up, down, left and right - 1 if they can; 0 if not). Give them another alterable value, representing either "not connected" (0), "connected but not visited" (1) or "connected and visited" (2).

    Now, let's say your furnace is located at 0,0 (the top left corner), and has a pipe leading to the right...

    + Pipe: If x_pos = 1
    + Pipe: If y_pos = 0
    + Pipe: If connect_left = 1
    -> Pipe: Set connected to 1
    -> Start fastloop "connect_pipes", -1 times

    That gives you one pipe object with a connected value of 1, and all the rest will have a value of 0.
    Each loop, you pick a random pipe object with a connected value of 1, and start checking neighbouring pipe objects, based on the left/right/up/down/values - if they can be connected but currently have a connected value of 0, set it to 1 instead, so they will be visited on a future loop. And then after you've checked the neighbours, you set the connected value to 2, to mark it as done.
    When there are no pipe objects with a connected value of 1, the process is finished, and you need to stop the fastloop. At this point, any pipe object that is connected to your furnace will have a connected value of 2, and all the rest will have a value of 0.

    The main things to note are:
    * Don't forget you need to check the up/down/left/right values of both pipe sections. eg. If two pipe sections are side-by-side, you need to check both the right value of pipe #1 and the left value of pipe #2.
    * Since the normal object scoping system doesn't allow this, you WILL need to store these and the x_pos and y_pos of one of the pipe objects in another "data storage" object (ie. another hidden active that you use purely to hold data in its alterable values), or I suppose you could use global values... It may also be easier to use nested loops to check neighbours.
    * You MUST manually stop the fastloop when finished, or it will continue forever and cause the app to freeze.
    * It's probably easier and more flexible if the furnace itself is a variant of the pipe object (you could be using qualifiers for the different types of pipe section, but I recommend avoiding them wherever possible).

    Edited once, last by MuddyMole (May 13, 2018 at 12:49 AM).

  • Thank you so much for help guys.
    But some questions.
    What is ADD in the code? Why it's divided by 8/4/2...
    Why there is selected x_pos to x_pos ("Pipe")/90 -> Why it's divided?
    ( Dir( "Pipe" ) and 8 ) / 8
    What are fixed values, and for what are they used in this example?

  • "AND" is a binary bitwise operator, which is a very complicated concept to explain (look on wikipedia if you're really interested).
    The idea however, is to take the individual values that say if a pipe can connect on the left, right, top and bottom, and then pack them into a single value, which we can use to set the animation frame.

    Start with a value of 0.
    If the pipe can connect with another pipe to the top, add 1.
    If it can connect with another pipe to the right, add 2.
    If it can connect with another pipe to the bottom, add 4.
    If it can connect with another pipe to the left, add 8.

    So, for example, an "L" shaped pipe would have a total value of 1 + 2 = 3.

    The important thing to realize is that any given total value, can only result from ONE possible combination of the numbers 1, 2, 4 and 8. For example, the only combination of those values that adds up to 6, is 2 and 4.
    That means that given any total value, it is possible to check if the pipe is able to connect in any given direction, which is exactly what those expressions with the "AND" operator are doing (there are other methods you could use instead).

    Note that although I only included double-ended pipe sections, the system allows for "T" and "+" shaped pipe sections, as well as single-ended pipe sections (dead-ends), without modification.


    Dividing the x and y coordinates by 90 just gives us grid coordinates instead of pixel coordinates, since each pipe object is 90x90 pixels in size. It's not strictly necessary, but it's convenient.
    Note that "X / 90" is NOT the same as "X / 90.0". When dividing by an integer (whole number; eg. 90), the result is automatically rounded down to an integer. When dividing by a float (eg. 90.0), the result remains a float.


    Fixed values are just unique identifiers which CF2.5 automatically assigns to each individual instance of every object.
    In this particular example, the "pick one at random" action is used to select a pipe object. It is followed by other events which need to select other pipe objects, but then later on I need to reselect the same pipe as before - and I can't use "pick one at random" again, because that might not pick the same pipe object again. Storing the fixed value is just a way of remembering which pipe object was selected.


    Bear in mind that what you're trying to achieve is not simple stuff - there's a reason most people just make platformers and shooters...

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!