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.

Why is this not turning all inactive welders on? (solved thanks to Meadea: use Enabled property to

Discussion in 'Programming Questions and Suggestions' started by RTM, Jan 4, 2015.

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

    Messages:
    285
    Code:
     void turnOnWelders(IMyGridTerminalSystem term, List<IMyTerminalBlock> welders)
            {
                int i_w = welders.Count;
                int i_tw_total = 0;
                var s_weld = String.Concat("Found ", i_w, " welders..");
                Debug(s_weld);
    
                if (welders.Count == 0) return;
                for (int i = 0; i < welders.Count; i++)
                {
                    if (welders[i].IsFunctional == false)
                    {
                        welders[i].GetActionWithName("OnOff").Apply(welders[i]);
                        i_tw_total++;
                    }
                }
                s_weld = String.Concat("Turned on", i_tw_total, " welders..");
                Debug(s_weld);
            }
    

    I'm stumped. Probably been at it for too long, it's one 0100 and I last ate at 0900...
     
    Last edited by a moderator: Jan 4, 2015
  2. Meadea Trainee Engineer

    Messages:
    22
    Does IsFunctional return that a welder is actually on, or is it just inherited from something? (i.e. to distinguish between IMyFunctionalBlock and other)

    EDIT:
    It's inherited, IsFunctional doesn't do what you think it does, I can't see anything obvious in the API that will get that information
    (Maybe try the detailed info thing? Not sure.)
     
    Last edited by a moderator: Jan 4, 2015
  3. RTM Apprentice Engineer

    Messages:
    285
    I dunno, but the script seemed to work most of the time, but would not work all the time.

    I mean, try it out..
     
  4. Meadea Trainee Engineer

    Messages:
    22
    IsFunctional is inherited from IMyCubeBlock, I'm pretty sure it serves to distinguish if a block is an IMyFunctionalBlock.

    Have you tried using welders.Enabled instead? * You might need to cast it to an IMyShipWelder interface, not sure

    I'd also recommend checking that the elements of the array are actually welders (the input isn't shown in the script) though that's not a problem if the locations where its being called are doing it


    I'd rather not start up Space Engineers, make a world and then run the script :/
     
    Last edited by a moderator: Jan 4, 2015
  5. Knsgf Junior Engineer

    Messages:
    538
    IsFunctional == true tells that the block integrity is above the red line. To check whether block is turned on use Enabled property:
    Code:
    if (welders[i].Enabled == false)
    
    You can also use "OnOff_On" action, which will turn the block on regardless of its current state.
     
  6. RTM Apprentice Engineer

    Messages:
    285


    Thanks!

    I oughta know better than to try to script tired..
     
    Last edited by a moderator: Jan 4, 2015
  7. RTM Apprentice Engineer

    Messages:
    285
    Also, usually you get IMyTerminalBlock list or reference? back, so it needs to be cast to IMyShipWelder..
     
    Last edited by a moderator: Jan 4, 2015
Thread Status:
This last post in this thread was made more than 31 days old.