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.

Programmable Block Find It's Own Name / Entity ID

Discussion in 'Programming (In-game)' started by Mortisfire, Aug 26, 2015.

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

    Messages:
    148
    Hey, was wondering how I can get a programming block to find its own name and entity ID. That way I can search for other blocks with the same entity ID.
     
  2. Malware Master Engineer

    Messages:
    9,663
    The programmable block has a Me property with its own programmable block, added by yours truly.

    You won't find another block with the same entity ID, though. They're unique.

    Other properties:
    TimeSpan ElapsedTime - the time elapsed since the previous run (0 on the first run)
    Action<string> Echo - Output a debug string to the details area
    string Storage - (a Keen original, not mine) - A string that allows you to pass data between gaming sessions. Slightly bugged at the moment, you may lose data when recompiling a script. I have a GitHub PR with a fix in it, but who knows if or when that will be merged given the current situation. I actually have several feature additions and bugfixes waiting
     
  3. Mortisfire Apprentice Engineer

    Messages:
    148
    Okay, great. The problem is I am spawning prefabs that attach together which sometimes have identical names. For example, I spawn two "Medium Hangar"s. Each prefab has a programmable block which controls a menu on an LCD. When the two programmable blocks are looking for the same named Text Panel, it will only find the first one and thus control the wrong one. I guess what I am looking for is the IMyCubeGrid Entity ID of the programmable block and then use that to find blocks with the same IMyCubeGrid Entity ID. Then after I find the blocks with that CubeGrid Entity ID, I will find in that list the blocks that have the name "MenuLCD" or something.

    My programming abilities are extremely limited, so if you could provide as much detail as possible I would appreciate it. Thank you.
     
    Last edited: Aug 27, 2015
  4. Malware Master Engineer

    Messages:
    9,663
    If you paste two prefabs onto the same ship, the grids are merged into one, and their entity IDs potentially regenerated - an entity ID must be unique. What you are proposing is not possible in this situation. The only way grids retain their identity is when connected via connectors.

    If you prefabs are connected via connectors and the grids are retained:
    (Be warned, this is from memory and might have errors)
    Code:
    List<IMyTerminalBlock> _blockList = new List<IMyTerminalBlock>();
    IMyTextPanel _menuLcd;
    
    public void Main(string argument) {
    	_blockList.Clear();
    	GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(_blockList, block => block.CustomName == "MenuLCD" && block.CubeGrid == Me.CubeGrid);
    	if (_blockList.Count > 0) {
    		_menuLcd = _blockList[0] as IMyTextPanel;
    	} else {
    		Echo("Can't find MenuLCD");
    	}
    }
    
     
    Last edited: Aug 27, 2015
  5. Mortisfire Apprentice Engineer

    Messages:
    148
    Okay so I think I'm going to move the menu to a mod. What I need is too complicated for the programmable block I think. I will probably just have to calculate the closest Text Panel with the name "LCDMenu".
     
  6. Malware Master Engineer

    Messages:
    9,663
    If you're going in that direction you can do that from within a programmable block. You can get each block's grid-relative position - unfortunately I don't have access to the game right now so I can't find the exact syntax, but it's either Position or GetPosition(). There's a bug with non-script structs however, so you'll need to jump through hoops to get the actual x/y/z values. If you're willing to use a mod script maybe that'll be easier until that bug is fixed :D
     
    • Like Like x 1
  7. Mortisfire Apprentice Engineer

    Messages:
    148
    Yeah, it just looks like it's going to be easier to make this a mod. This is for a scenario anyway so I can add mods after all. Thanks for the help though. Appreciate it.
     
Thread Status:
This last post in this thread was made more than 31 days old.