Something which just turns off / on all the lights on your ship. Has some other useful sub-methods which can be used for other purposes. Code: void Main() { List<IMyTerminalBlock> blocks; blocks = new List<IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(blocks); if (blocks.Count == 0) return; IMyRadioAntenna antenna = blocks[0] as IMyRadioAntenna; //All this works blocks.Clear(); GridTerminalSystem.GetBlocksOfType<IMyLightingBlock>(blocks); for (int i = 0; i < blocks.Count; i++) { BlockToggle((IMyFunctionalBlock)blocks[i]); } antenna.SetCustomName("Hello Galaxy!"); Beep(); } void BlockToggle(IMyFunctionalBlock block) { BlockAction(block, "OnOff"); } void BlockEnable(IMyFunctionalBlock block) { BlockAction(block, "OnOff_On"); } void BlockDisable(IMyFunctionalBlock block) { BlockAction(block, "OnOff_Off"); } void Beep() { IMySoundBlock speaker = GridTerminalSystem.GetBlockWithName("Test Speaker") as IMySoundBlock; if (speaker == null) return; BlockAction(speaker, "PlaySound"); } void BlockAction(IMyFunctionalBlock block, string action) { var foundAction = block.GetActionWithName(action); if (foundAction != null) { foundAction.Apply(block); } }
I'd love to understand this, I might be learning this in the future. In an avalanche, not one snowflake feels responsable. -Voltaire, during the French Revolution.