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.

Script Not Updating Display Correctly

Discussion in 'Programming Questions and Suggestions' started by Martin R Wolfe, Feb 24, 2017.

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

    Messages:
    80
    I am trying to find out why the left-hand computer in the image below which is running the display update script is not updating its own display properly. The script is supposed to find the display directly above each program block and show its detailed info. The other 3 displays are updating correctly.

    This is what is happening on the displays:-

    [​IMG]

    The detailed info for the left-hand computer is shown in the following image:-
    [​IMG]

    The left-hand computer is running the following script:-
    Code:
    //Configuration constants 
    private const double StartDelay=4; 
     
    //Private variables 
    private DateTime SystemLoadTime; 
    private string ConfigString; 
     
    public Program() { 
        SystemLoadTime=DateTime.Now; 
     
        //Load config from Storage if exists otherwise from CustomData 
        if(Storage!="") ConfigString=Storage; 
        else ConfigString=Me.CustomData; 
        Initialise(); 
    } 
     
    public void Save() { 
        Storage=ConfigString; 
    } 
    public void Main(string argument) {
        //Delay by StartDelay to give save game time to fully load 
        if((DateTime.Now-SystemLoadTime).TotalSeconds<StartDelay) return; 
     
        //Extract the commands from the arguments 
        List<ParameterWithValue> CommandLines=ParametersWithValuesFromString(argument); 
     
        //Load the blocks to the classes
     
        //Process the commands 
        foreach(ParameterWithValue aCommand in CommandLines) 
            switch(aCommand.Name){ 
            case "REBOOT":  //REBOOT command must be the only argument with no params 
                if((CommandLines.Count==1) & (aCommand.Values.Count==0)){ 
                    Echo(Me.CustomName + ": REBOOTING"); 
                    ConfigString=Me.CustomData; 
                    Initialise(); 
                    } 
                break; 
            case "TimerPing": 
                Echo(Me.CustomName + ": Status Ok");
                IMyCubeGrid CubeGrid=Me.CubeGrid; 
                Vector3I Position=Me.Position; 
                Matrix aMatrix; 
                Matrix invMatrix; 
                List<IMyProgrammableBlock> ProgBlocks=new List<IMyProgrammableBlock>(); 
                GridTerminalSystem.GetBlocksOfType<IMyProgrammableBlock>(ProgBlocks,   
                    x=>(x.CubeGrid==CubeGrid)); 
                Echo("Computer count: " + ProgBlocks.Count); 
                List<IMyTextPanel> Displays = new List<IMyTextPanel>(); 
                foreach(IMyProgrammableBlock aProgBlock in ProgBlocks){ 
                    aProgBlock.Orientation.GetMatrix(out aMatrix); 
                    invMatrix=Matrix.Invert(aMatrix);
                    Vector3D dTextPanelLoc= Vector3D.Transform( 
                        (Vector3D.Transform(aProgBlock.Position,aMatrix)+(new Vector3D(0,1,-1))),invMatrix);
                    GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(Displays, 
                        x=>((x.CubeGrid==CubeGrid)&&((Vector3D)(x.Position))==dTextPanelLoc));   
                    Echo("Name: " + aProgBlock.CustomName);
                    if(Displays.Count>0){
                        Displays[0].ShowPublicTextOnScreen();   
                        Displays[0].WritePublicText(aProgBlock.DetailedInfo, false);   
            }
        } 
     
                break; 
            default: 
                Echo(Me.CustomName + ": Error unrecognised command: " + aCommand.Name); 
                break; 
            } 
     
        //Free the blocks from the classes 
    }
    private void Initialise(){
    }
     
    public struct ParameterWithValue {   
        public string Name;   
        public List<string> Values; 
        public ParameterWithValue(string aCommandLine){ 
            List<string> CommandWithParams = new List<string>(aCommandLine.Split(new char[] {':'},2)); 
            if(CommandWithParams.Count<2) CommandWithParams.Add(""); 
            Name=CommandWithParams[0]; 
            Values=new List<string>(); 
            foreach(string aParameter in (new List<string>(CommandWithParams[1].Trim().Split(',')))){ 
                if(aParameter.Trim()!="") Values.Add(aParameter.Trim()); 
            } 
        } 
    }
     
    static public  List<ParameterWithValue> ParametersWithValuesFromString(string ParameterString){ 
        //Extract the commands from the arguments 
        List<ParameterWithValue> ParametersWithValues=new List<ParameterWithValue>();   
        foreach(string aCommandLine in (new List<string>(ParameterString.Trim().Split(';')))) 
            if(aCommandLine.Trim()!="") ParametersWithValues.Add(new ParameterWithValue(aCommandLine.Trim())); 
        return ParametersWithValues; 
    }
    
     
Thread Status:
This last post in this thread was made more than 31 days old.