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 with controlling groups

Discussion in 'Programming (In-game)' started by Byful, Jun 7, 2020.

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

    Messages:
    3
    So I'm wanting to write up a script that sums up all thrust directions. compares the available newton force with current ship weight. Then uses the delta-v formula and determines if the ship had enough fuel for a one-way trip or 2-way trip. Gonna try to implement some sort of auto-pilot feature so a ship doesn't ram full speed into a station.
    I've never used the List command while programming so it was no surprise when it was giving me errors. If anyone can give me pointers with groups it would help a lot, or if theirs a way I can avoid the groups method by like finding all the (Backward) and (Forward) thrust the game automatically adds to the names of thrusters, I can avoid the 6 groups in the terminal and probably reduce the script a bit.

    This is what i've got currently, and it gives me an object could not be reference error

    //IMyGyro ShipGyro;
    //, S_Thrust, A_Thrust, D_Thrust, Space_Thrust, Ctrl_Thrust
    IMyGasTank FuelTank;
    IMyThrust ForwardThrust;
    double FuelPercent = 0.0f;
    //FuelRemaining = 0.0f
    public Program()
    {
    Runtime.UpdateFrequency = UpdateFrequency.Update100;
    IMyBlockGroup W_Thrust = GridTerminalSystem.GetBlockGroupWithName("W Thrusters") as IMyBlockGroup;
    List<IMyTerminalBlock> FowardThrust = new List<IMyTerminalBlock>();
    W_Thrust.GetBlocks(FowardThrust);
    //A_Thrust = GridTerminalSystem.GetBlockGroupWithName("A Thrusters") as IMyThrust;
    //S_Thrust = GridTerminalSystem.GetBlockGroupWithName("S Thrusters") as IMyThrust;
    //D_Thrust = GridTerminalSystem.GetBlockGroupWithName("D Thrusters") as IMyThrust;
    //Space_Thrust = GridTerminalSystem.GetBlockGroupWithName("Space Thrusters") as IMyThrust;
    //Ctrl_Thrust = GridTerminalSystem.GetBlockGroupWithName("Ctrl Thrusters") as IMyThrust;
    //ShipGyro = GridTerminalSystem.GetBlockGroupWithName("Ship Gyros") as IMyGyro;
    FuelTank = GridTerminalSystem.GetBlockWithName("Hydrogen Tank") as IMyGasTank;
    }

    public void Save()
    {

    }

    public void Main()
    {
    //FuelRemaining = FuelTank.Capacity * FuelTank.FilledRatio;
    FuelPercent = FuelTank.FilledRatio * 100;
    FuelPercent = Math.Round(FuelPercent, 2);
    Echo("Ship fuel - " + "%" + FuelPercent.ToString());
    ForwardThrust.ThrustOverride = 5000.0f;
    }
     
    Last edited: Jun 7, 2020
  2. Ronin1973 Master Engineer

    Messages:
    4,964
    You've defined a List but you haven't populated it with anything. There's nothing in the list when you're 'Getting Blocks' W_Thrust.GetBlocks(FowardThrust). There are also some other problems in the code. I would look for some coding examples, especially use of the constructor and Lists. There should be plenty to read in the Programming Guides and Tools forum.
     
  3. Byful Trainee Engineer

    Messages:
    3
    Yea, I've join discord and realized I know next to nothing about programming so I've been watching a crash course on C#, I've already scrapped the code and planned another in the future but for now. I'm gonna code properly. I had previously learned coding from stripping/reading other peoples code so I ended up missing a large coding knowledge. I can already see a way to make it better. Thank ya.
     
  4. Ronin1973 Master Engineer

    Messages:
    4,964

    Cool. It can be pretty rewarding once you get into the flow of it. I just hobby-code from time to time... but you can still get a lot done with just some very basic knowledge.
     
Thread Status:
This last post in this thread was made more than 31 days old.