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.

Timer block issue with script?

Discussion in 'General' started by Transistor, Aug 31, 2015.

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

    Messages:
    18
    Hey all, I'm working on getting an oxygen monitor going for all my rooms in my station going, I have a script with snags the oxygen levels great, and now I'm working on getting it to refresh itself. I thought this would be as simple as taking a timer block, within the "Setup Actions" window I added my programmable block, set it to "run", gave it no arguments as my script doesn't use them, and then added another action to "start" the block. The block is looping like I'd expect it to, I debugged it with an interior light to ensure I wasn't doing it wrong, but my code is never update the LCD panel which is displaying my information.

    Is this the proper way to repeat a script? Is there something wrong that you can see immediately? This is a bit perplexing because I seem to have had this issue with every script that employs timer blocks with scripts.
     
  2. Malware Master Engineer

    Messages:
    9,866
    As long as your script is actually run, there's no issue.

    Common issues:
    First, obviously, check your ownership. You probably already did that :)
    Second: Are you sure your screens are set to display the right text? It can be set to display either the private or the public text, and you must make sure you update the right text.
    Third: This is how it used to be, at least: I believe you must make sure your LCDs are actually refreshed, by using the ShowPublicTextOnScreen() (or private) method after your text update is done. At least I think that's its name... it's something similar at least. In the beginning you even had to swap between ShowTextureOnScreen() and ShowPublicTextOnScreen(), I don't know if this is still required - I don't think so.
     
  3. jhnwgacy Trainee Engineer

    Messages:
    81
    Hi.
    LCD were buggy last time i used them in scripts (this was 5-6 months ago , so i don't know were they patched or not.) Your script can update info, but LCD doesn't redraw screen.
    My func for text output was like:

    void TextOutput(string Screen, string Output="")
    {
    IMyTextPanel ScreenObj = GridTerminalSystem.GetBlockWithName(Screen) as IMyTextPanel;
    if (ScreenObj!=null){
    ScreenObj.ShowTextureOnScreen();
    if (Output!=""){
    ScreenObj.WritePublicText(Output);
    }
    ScreenObj.ShowPublicTextOnScreen();
    ScreenObj.GetActionWithName("OnOff_On").Apply(ScreenObj);
    }
    }

    And it still works on my ships, so you can try using it.
     
  4. The Judge Trainee Engineer

    Messages:
    63
    I don't script myself yet. But i do use the Configurable Automatic LCDs script from the workshop. This updates LCDs with various text and the refresh is triggered by a timer. It works great (i'm looking at it right now on my other screen).

    Some source digging would give you some help I am sure.
     
  5. Harrekin Master Engineer

    Messages:
    3,077
    Are you using lists?

    When it's looping check for an error message on the programmable block in the K menu.

    Sometimes you will try display a non existent index and it will cause the LCD to not update because the code won't actually run despite it compiling properly.
     
  6. Sinbad Senior Engineer

    Messages:
    2,788
    check the error reporting from the k menu, select the pb, then hit run. look in the bottom right corner. exceptions show up here. often a script will compile fine, but still has a bug that halts it. often the exception details don't provide enough information to localise the bug.
    this method is usefull:
    Code:
    Echo("here");
    
    put it somewhere in your script. it prints to the same place in the k menu. if you don't see "here" printed before the error details, the script halted before it got to "here". move it up and run it again. keep doing that until you see "here". you can narrow the bug down to a single line that way.
    you can also echo out just about anything, as long as its formated as a string.
    Code:
    Echo(Format.String({0:0},ThisFloatValue);
    
    will output thisfloatvalue as a string to the k menu. handy for keeping an eye on variables without having to output to a text panel.

    also, all that mucking about with the text panels as posted above isn't required any more.
    Code:
    ThisPanel.WritePublicText("hello world");
    
    is sufficient.
    I have a script that runs once per game tick (60 times a second) and does 6 read/writes to a text panel per tick with no errors, and the text is always visible.
     
  7. Transistor Trainee Engineer

    Messages:
    18
    It was the ownership! I'm fairly new with some of these newer blocks in Space Engineers so it's the last thing I've been checking. Keeping that in mind from now on lol. Thanks.
     
    • Like Like x 1
  8. Malware Master Engineer

    Messages:
    9,866
    Glad to hear it was something simple :)Don't worry, you're not alone. It's one of the most common mistakes people do when starting out with the programmable block.
     
  9. Sinbad Senior Engineer

    Messages:
    2,788
    i still do it.
    "ill just add another panel/timer to this... why wont it work?"
    every. single. time.
    there really needs to be a changeable default ownership setting.
     
  10. Malware Master Engineer

    Messages:
    9,866
    Yes, maybe just simply duplicate whatever you set last for any new block. That would be great.
     
Thread Status:
This last post in this thread was made more than 31 days old.