1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

Noob Question about Groups and Doors

Discussion in 'Programming Questions and Suggestions' started by Mighty Annihilator, Apr 6, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Mighty Annihilator

    Mighty Annihilator Trainee Engineer

    Messages:
    4
    I'm really not sure how search works on this forum, so if it was answered before, I apologize in advance.

    I'm trying to make an automated airlock using the airtight doors (modded ones, anyway), so I need to know two things - how to work with groups (since the basic guide put up by Keen doesn't exactly explain that) and if there is some way to know that door has fully extended.
     
  2. plaYer2k

    plaYer2k Master Engineer

    Messages:
    3,160
    groups are just lists of blocks in combination with a name.
    You iterate through the list and gather the information and/or apply an action to them.

    As for doors, thay only got two states which are open or closed. They do not contain the accessible state isclosing or isopening.
    I guess even internally they only got these two, which is probably the reason for their airlock bug too.

    To check the member of a class use either the documentation within your SE folder or use an inspector like ILspy.
    I personally prefer ilspy as that is always up to date, independent, has more features and looks better that the the windows help.

    Sadly i cant go into more details as i am mobile right now.
     
  3. Mighty Annihilator

    Mighty Annihilator Trainee Engineer

    Messages:
    4
    Well, so far I'm only getting errors that "block group can't be turned into a list"... Probably doing something wrong, since I don't know the first idea about how to get them and am trying to use a code snipped I stole from someone's script on workshop. Could you explain how to get group with a certain name, and what type will the items in list have?
     
  4. plaYer2k

    plaYer2k Master Engineer

    Messages:
    3,160
    Alright back home, lets go into detail.

    You want to go through blockgroups. So you need to know what a blockgroup is first.

    Code:
        public interface IMyBlockGroup
        {
            List<IMyTerminalBlock> Blocks { get; }
            string Name { get; }
        }
    As you can see, an IMyBlockGroup contains a list of IMyTerminalBlocks called Blocks aswell as a string for the name called Name.

    You can get a list of IMyBlockGroup elements through the IMyGridTerminalSystem
    Code:
    List<IMyBlockGroup>  IMyGridTerminalSystem.BlockGroups
    The only accessible IMyGridTerminalSystem for a programmable block is the GridTerminalSystem so far.

    So what you need to do is get the list of blockgroups for the accessible gridterminalsystem, go through all looking for a name that matches a search string, either fully or partially, and if you found a matching group then you have to do something with all the blocks stored in the list within the blockgroup.

    Here is a small example of how you could do it without many hull functions.
    Code:
    // This is the string we use to find a matching group
    const string groupMatch = "Airlock doors";
    
    void main()
    {
        // go through all blockgroups for our gridterminalsystem
        for(int i = 0; i < GridTerminalSystem.BlockGroups.Count; i++)
        {
            // check if the current blockgroup is not a matching group
            // if it aint, we "continue" with the next iteration for the for-loop
            if(!GridTerminalSystem.BlockGroups[i].Name.StartsWith(groupMatch))
                continue;
    
            // We found a matching block group name as otherwise it would have skipped the iteration
    
            // Now we go through a blockgroups list of blocks
            for(int j = 0; j < GridTerminalSystem.BlockGroups[i].Blocks.Count; j++)
            {
                // DO SOMETHING WITH THE BLOCK HERE
                GridTerminalSystem.BlockGroups[i].Blocks[j];
            }
        }
    }
    I hope that the in-code comments are good enough for you to understand.
    As i can not run SE, i can not guarantee that the code is 100% correct as it is.

    Good luck.
     
    Last edited: Apr 7, 2015
  5. MisterSwift

    MisterSwift Apprentice Engineer

    Messages:
    367
    You left out the .Name when checking the blockgroups' names, and the void before Main() :p Otherwise it works perfectly

    Code:
      if(!GridTerminalSystem.BlockGroups[i].Name.StartsWith(groupMatch))
     
  6. plaYer2k

    plaYer2k Master Engineer

    Messages:
    3,160
    alright fixed :)
     
  7. Mighty Annihilator

    Mighty Annihilator Trainee Engineer

    Messages:
    4
    Thank you for explaining! The piece of code I had treated the groups as lists somehow, so it got me confused.
    Um... anyone knows what the "Common Language Runtime detected an invalid program" exception means? Nevermind, apparently SE doesn't support foreach.
     
    Last edited: Apr 7, 2015
  8. plaYer2k

    plaYer2k Master Engineer

    Messages:
    3,160
    Could you provide the code?

    I couldnt run the game for almost 4+ weeks now so checking the code is the easiest to find it.
    Also iirc the error message occured for several different reasons.
     
Thread Status:
This last post in this thread was made more than 31 days old.