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.

Switch a Group of Atmospheric Thrusters On/Off using IF condition

Discussion in 'Programming Questions and Suggestions' started by WOLFIN4TOR, Jan 13, 2018.

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

    Messages:
    1
    I've tried to create my first script here, but as I'm new to scripting(First time C# and for Space Engineers) I tried to create my code using snippets of other codes, with little success...

    The code:

    public Program()
    {
    Runtime.UpdateFrequency = UpdateFrequency.Update10;
    }

    public void Main(string argument, UpdateType updateSource)

    {

    List<IMyTerminalBlock> templist0 = new List<IMyTerminalBlock>();
    List<IMyTerminalBlock> thrustlist0 = new List<IMyTerminalBlock>();
    GridTerminalSystem.GetBlocksOfType<IMyThrust>(templist0);
    IMyThrust thrust0;

    if(templist0.Count != 0){

    for(int i = 0; i < templist0.Count; i++){

    if(templist0.CustomName.Contains("LATAAT")){

    thrustlist0.Add(templist0);

    }

    }

    IMyMotorStator rotor = GridTerminalSystem.GetBlockWithName("ATMOSrotor") as IMyMotorStator;

    var a = rotor.GetValueFloat ("Angle");

    if (a >=80) {

    for(int i = 0; i < thrustlist0.Count; i++){
    thrust0 = thrustlist0 as IMyThrust;
    thrust0.GetActionWithName("OnOff_On").Apply(thrust0);
    }

    }
    else
    {
    for(int i = 0; i < thrustlist0.Count; i++){
    thrust0 = thrustlist0 as IMyThrust;
    thrust0.GetActionWithName("OnOff_Off").Apply(thrust0);
    }
    }
    }
    }


    The error message is: "Caught exeption during execution of script:Object reference not set to an instance of an object"

    Unfortunately I can't figure out what exactly or where the problem is.:?

    The program should enable all amospheric thrusters, labelled "LATAAT", when the Rotor named "ATMOSrotor" reaches an angle of >=80 degrees. Thanks in advance :)
     
Thread Status:
This last post in this thread was made more than 31 days old.