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.

Help GridterminalSystem in my own class throw exception.

Discussion in 'Programming Questions and Suggestions' started by meloncrashed, Oct 14, 2017.

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

    Messages:
    3
    Code:
    namespace IngameScript
    {
        internal partial class Program
        {
            internal class Vehicle: MyGridProgram
            {
                internal IMyShipController _vehicleController;
                internal int BaseMass => _vehicleController.CalculateShipMass().BaseMass;
                internal int PhysicalMass => _vehicleController.CalculateShipMass().PhysicalMass;
    
    
                internal Vehicle(string vehicleControllerName)
                {
                    _vehicleController = GridTerminalSystem.GetBlockWithName(vehicleControllerName) as IMyShipController;
                }
            }
        }
    }
    program block always throw exception.
    There is a way to use GridTerminalSystem in my own class?
     
  2. Martin R Wolfe Trainee Engineer

    Messages:
    80
    GridTerminalSystem is a proprety of the GridProgram class. To access it from a user class you have to pass the GridProgram that creates the instance of a user class by that user classes constructor
    eg:-
    Code:
    	private MyInstrumentUnit InstrumentUnit;
    
            public void main(string Args)
    	{
    		InstrumentUnit = new MyInstrumentUnit( this );
    
    		// Code to do things goes here
    
    		return;
    	}
    
            private class MyInstrumentUnit
            {
                private MyGridProgram CallingGridProgram;
    
                private IMyGridTerminalSystem GridTerminalSystem => CallingGridProgram.GridTerminalSystem;
                private IMyProgrammableBlock Me => CallingGridProgram.Me;
                private Action<string> Echo => CallingGridProgram.Echo;
    
                public List<MyStage> Stages { get; private set; }
    
                public MyInstrumentUnit(MyGridProgram ThisProg)
                {
                    CallingGridProgram = ThisProg;
    
                    Stages = new List<MyStage>();
                    return;
                }
            }
    
     
    Last edited: Oct 25, 2017
    • Like Like x 1
  3. meloncrashed Trainee Engineer

    Messages:
    3
    Thanks for your help :)
     
Thread Status:
This last post in this thread was made more than 31 days old.