User Tag List

Results 1 to 6 of 6

Thread: Search for objects connection - Array

  1. #1
    Clicker Fusion 2.5 (Steam)

    Join Date
    Nov 2016
    Posts
    41
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Search for objects connection - Array

    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

  2. #2
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,307
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,341
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    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).

  4. #4
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,341
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Just a quick and simple example:
    Pipes.mfa
    (graphics are stolen from the internet)

  5. #5
    Clicker Fusion 2.5 (Steam)

    Join Date
    Nov 2016
    Posts
    41
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,341
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    "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...

Similar Threads

  1. how to search objects in event editor?
    By schip in forum Fusion 2.5
    Replies: 2
    Last Post: 12th June 2016, 07:00 AM
  2. Search function - Search a Word in a couple of strings for example
    By iamjot in forum iOS Export Module Version 2.0
    Replies: 3
    Last Post: 22nd February 2012, 03:51 PM
  3. What objects have search options?
    By Tiny in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 26th January 2011, 04:48 AM
  4. Connection Objects
    By Puglord in forum The Games Factory 2 - Technical Support
    Replies: 2
    Last Post: 9th June 2007, 08:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •