2

I have a part that is a rectangle of 1200mm x 400mm x 400mm, this part can be divided into 3 equal sizes, within these equal sizes I need to Dock different parts. I have set a Docking Range for every 400mm (which is fine) I have 3 style of parts that need to Dock into the 400mm gaps, so I have set on the main 1200 part 3 KEYS (bridgePos1InfillType, bridgePos2InfillType, bridgePos3InfillType) and currently when I dock a part inside these I set the TYPE that was docked...

        "mask": "cubby",
            "position": "{0, 0, 40}",
            "stepEnd": "{800, 0, 0}",
            "rotation": "{0, 0, 0}",
            "condition": "(((configID=='v2')||(configLadderID=='v2'))&&(cubeHeight==400))",
            "maxConnections": 1,
            "stepX": 400,
            "stepY": 0,
            "stepZ": 0,
            "assignmentScripts": {
                "onDock": "index = connection.index; 
                if(index=='0'){bridgePos1InfillType='cubby'};
                if(index=='1'){bridgePos2InfillType='cubby'};
                if(index=='2'){bridgePos3InfillType='cubby'}",
                "onUpdate" : "",
                "onUnDock": "index = connection.index; 
                if(index=='0'){bridgePos1InfillType='blank'};
                if(index=='1'){bridgePos2InfillType='blank'};
                if(index=='2'){bridgePos3InfillType='blank'}"
            } 

But what I want to happen is when I then try to docking a different part (using Docking Range) it should not let me as the InFillType is not BLANK

this is my next part to dock but how do I check to see if the Docking Range Position in already taken or that the bridgePos1InFillType is not BLANK...

     {
            "mask": "cupboard400x400",
            "position": "{0, 0, 40}",
            "stepEnd": "{800, 0, 0}",
            "rotation": "{0, 0, 0}",
            "condition": "index = connection.index; 
            (((configID=='v2')||(configLadderID=='v2'))&&(cubeHeight==400))",
            "maxConnections": 1,
            "stepX": 400,
            "stepY": 0,
            "stepZ": 0
        },
Michael Todd
  • 211
  • 1
  • 3

1 Answers1

2

You can utilize internal value called condition in all condition statements, like this:

"condition": "
    /* you probably want to check if you're in preview, otherwise you could delete it right after docking, if the condition result becomes false */
    if (connection.isPreview) {
        /* then checking against which internal var to check this */
        if (connection.index == 1) { condition = bridgePos1InfillType == 'blank'; }
        ...
        /* then you can do further checks like */
        condition = condition && (!maximumLoadExceeded);
    } else {
        /* if it is already there, just don't worry & keep it */
        condition = true;
    }
"

There is connection.index or connection.position to check the current position in the range's array. For 2D ranges, I recommend approach of computing the indices from connection.position. For 1D range, connection.index works just fine. See https://docs.roomle.com/scripting/resources/200_80_dockingbasics.html#docking-ranges and https://docs.roomle.com/scripting/resources/200_140_advanceddockinglogic.html#docking-ranges

I also see that an array would be good for you. If you worry only about whether there is something already docked, you could do an array of booleans occupied = [0,0,0] and then access the values using get(self.occupied, connection.index) in condition and use the set function in assignment scripts. If you need to also know what is occupied, RoomleScript unfortunately only supports arrays of numbers. A possible solution would be to have a 1:1 constant numeric identifier for every type.

See also https://docs.roomle.com/scripting/resources/200_40_roomlescript.html#arrays

Jiri Polcar
  • 306
  • 1
  • 4