Dieser Artikel ist auch in Deutsch verfügbar. Um ihn in Deutsch zu lesen klicke hier.
Finally, I wanted to have a look now at in-game programming in Space Engineers, not only because I’m writing C# programs since a couple of years. Until now I wrote a little kind of tutorial and published it on this blog and surprisingly I saw that my script (below) has 12 followers now, although it’s just a simple script. Apart from that I will publish all scripts on this blog here and explain them a bit. You will find a link to the Steam Workshop-Site if available below the code.
Note for English readers:
I can not promise to translate every article into English but I will try to do so. It is possible that it can take some time until I publish it in English.
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
for(int i = 0; i < blocks.Count; i++)
First of all, I initialise the List blocks which we need to cache all our blocks within the Grid. With GridTerminalSystem we gain access to all block within that current grid.. In this case I want to get all blocks, therefore I use the type IMyTerminalBlock that is used by all blocks inside the game.
Next I use the for-loop to iterate through each block. By the way: I’m just using the for-loop because the game has some problems with foreach-loops, mostly on 64-bit systems.
Then I check with !blocks[i].IsFunctional if this block is functional. This means, in Space Engineers, that the block is below the red line. If this is the case, the block shall be visible on our HUD. I do that with blocks[i].RequestShowOnHUD(true). I can’t do it with ShowOnHUD because this is an readonly property.