1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

MERGE block lock-state checking.

Discussion in 'Programming Questions and Suggestions' started by rox-mj, Jan 19, 2016.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. rox-mj

    rox-mj Trainee Engineer

    Messages:
    21
    Anyone know how to check Merge block "locked" or "connected" state? (when it in connection with other Merge block or not)
    Method IsFunctional seems not working with it.
     
  2. Wicorel

    Wicorel Senior Engineer

    Messages:
    1,263
    I don't see any properties or actions that give that information. Sorry.
     
  3. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    I have used a workaround which checks for a unique block name on the other side.
    I've also used timers to achieve a 'hand shake' only when the merge locks.
    There are work arounds, but a boolean property would be very useful.
     
  4. JoeTheDestroyer

    JoeTheDestroyer Junior Engineer

    Messages:
    573
    If a merge block is "merged", there must be another merge block in the proper position relative to it on the same grid. So check for that:
    Code:
    bool IsMerged(IMyShipMergeBlock mrg1)
    {
      //Find direction that block merges to
      Matrix mat;
      mrg1.Orientation.GetMatrix(out mat);
      Vector3I right1=new Vector3I(mat.Right);
     
      //Check if there is a block in front of merge face
      IMySlimBlock sb=mrg1.CubeGrid.GetCubeBlock(mrg1.Position+right1);
      if(sb==null) return false;
     
      //Check if the other block is actually a merge block
      IMyShipMergeBlock mrg2=sb.FatBlock as IMyShipMergeBlock;
      if(mrg2==null) return false;
     
      //Check that other block is correctly oriented
      mrg2.Orientation.GetMatrix(out mat);
      Vector3I right2=new Vector3I(mat.Right);
      return right2==-right1;
    }
    
    Will work for vanilla blocks, but larger moded blocks will fail. If that's important, you could probably work around that by using cubeblock Min & Max.
     
    • Informative Informative x 3
  5. rox-mj

    rox-mj Trainee Engineer

    Messages:
    21
    I use megre block as a base for automated creating torpedoes by the moving welderramp + projector. So torpedoes appears right on merge powered and connected. The problem is not to allow ramp move if torpedo already present.
    I tried something simple like this: if (!merge1.IsMerged) { than run construction process } else { not allowed }.
    But received the message:
    'Sandbox.ModAPI.Ingame.IMyShipMergeBlock' does not contain a definition for 'IsMerged' and no extension method 'IsMerged' accepting a first argument of type 'Sandbox.ModAPI.Ingame.IMyShipMergeBlock' could be found, are you missing a using directive or an assembly reference?
    (same story with "IsFunctional") As previously said, no boolean property like this.
    So I found workaround witn sensor block as logical variable between different programmable blocks. (Sensor is not used for its intended purpose, just turned-off). When torpedo constructed, "LeftExtend" becomes = 3". When torpedo went to a happy journey, "LeftExtend" returns back to = 1".

    JoeTheDestroyer, thank you. Took this code for the future. I'll try it in my experiments))
     
    Last edited: Jan 21, 2016
Thread Status:
This last post in this thread was made more than 31 days old.