Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

How do I create a list of all battery blocks on a grid except those in a certain group?

Discussion in 'Programming Questions and Suggestions' started by Sticky32, Jul 29, 2019.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Sticky32 Trainee Engineer

    Messages:
    7
    I've currently gotten around the problem by using "Reserve Power" as a block name instead of a group name, but it's not exactly an ideal solution because the script uses groups for everything else.


    // Get Batteries
    List<IMyBatteryBlock> ListBattery = new List<IMyBatteryBlock>();
    GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(ListBattery, l => !l.CustomName.Contains(strReservePower));


    // Get Reserve Power
    List<IMyBatteryBlock> ListReservePower = new List<IMyBatteryBlock>();
    GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(ListReservePower, l => l.CustomName.Contains(strReservePower));
     
  2. mojomann71 Senior Engineer

    Messages:
    1,669
  3. Mollymawk Trainee Engineer

    Messages:
    94
    List<IMyTerminalBlock> BadBatteries = new List<IMyTerminalBlock>();
    List<IMyBatteryBlock> GoodBatteries = new List<IMyBatteryBlock>();

    GridTerminalSystem.GetBlockGroupWithName("NameOfGroup").GetBlocks(BadBatteries) ;

    GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>( GoodBatteries, blk => !BadBatteries.Contains(blk)) ;


    not saying its the best way, as you are wasting time processing unwanted stuff.

    are there other ways to identify the blocks you do want? like blk => blk.CubeGrid.IsSameConstructAs( Me.CubeGrid )
    or
    Me.CubeGrid == blk.CubeGrid
    you could then put your reserve batteries on a sub grid or connected construct.
     
    Last edited: Jul 31, 2019
Thread Status:
This last post in this thread was made more than 31 days old.