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.

Toggle Show On Hud?

Discussion in 'Programming Questions and Suggestions' started by dudeman02379, Jan 15, 2015.

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

    Messages:
    12
    Is there a way to toggle the ShowOnHUD propery for a block? I tried RequestShowOnHUD(bool) but it didn't seem to work. I also don't see an action for it.

    EDIT:Never mind it worked fine. I messed up elsewhere in my code. Another question though....

    I am trying
    mytimer.GetActionWithName("OnOff_On").Apply(mytimer);
    mytimer.GetActionWithName("TriggerNow").Apply(mytimer);
    mytimer.GetActionWithName("Start").Apply(mytimer);
    This turns my timer on but never starts it running. So the events tied to the timer don't start. any ideas?
    I decided to post the whole script as i know that makes it much easier to help. The timer does turn on but does not start.

    <div>void Main()
    {
    IMyTimerBlock tmr = (IMyTimerBlock)GridTerminalSystem.GetBlockWithName("GPS Timer");

    List&lt;IMyTerminalBlock> blocks = new List&lt;IMyTerminalBlock>();
    GridTerminalSystem.GetBlocksOfType&lt;IMyCockpit>(blocks);

    IMyCockpit cp = blocks[0] as IMyCockpit;

    if (tmr.Enabled)
    {
    cp.RequestShowOnHUD(false);
    cp.SetCustomName("Scout");

    tmr.GetActionWithName("Stop").Apply(tmr);

    tmr.GetActionWithName("OnOff_Off").Apply(tmr);
    }
    else
    {
    tmr.GetActionWithName("OnOff_On").Apply(tmr);

    cp.RequestShowOnHUD(true);
    tmr.GetActionWithName("TriggerNow").Apply(tmr);
    tmr.GetActionWithName("Start").Apply(tmr);
    }
    }
    </div>
     
    Last edited by a moderator: Jan 15, 2015
  2. Textor Junior Engineer

    Messages:
    775
    I had this exact problem this evening. I ended up cutting and pasting the entire grid I was using into a new world, which fixed the issue. It seems like there is some sort of bug in the code regarding timers, but I don't have enough data to report it yet.
     
  3. dudeman02379 Trainee Engineer

    Messages:
    12
    I'm thinking it may be a race condition. The timer is issued the command to turn on, then it's issues the command to trigger and start. But it can't start because it's still trying to turn on. Like the GetActionWithName method does not block so execution continues even though it isn't complete.
    Totally just a theory but here is how I tested

    tmr.GetActionWithName("OnOff_On").Apply(tmr);

    while (!
    tmr.Enabled)
    {

    cp.RequestShowOnHUD(true);
    tmr.GetActionWithName("TriggerNow").Apply(tmr);
    tmr.GetActionWithName("Start").Apply(tmr);
    }

    This ended up looping so many times that is brought the server to a hault for a few minutes and I ended up with the "code too complex" message. So I believe this tells me the timer wasn't actually on yet. The fix would be to add a sleep type function to wait a few seconds to let the timer fully enable but as far as I know we don't have that ability right now without involving some other programming blocks and possibly timers.
     
Thread Status:
This last post in this thread was made more than 31 days old.