MDK-SE
MDK-SE copied to clipboard
Indent reset at certain level
VS2017 Community MDK-SE v1.2.22
Indenting depth in the output gets reset after a certain depth. This example below shows a fragment of the output. It doesn't seem to matter what's going on in the code; when the indent level (or, possibly, the nesting level) reaches 4 deep in the initial source, it drops to 0 in the output.
Source fragment:
void Init() {
GridTerminalSystem.GetBlocksOfType(dummy, block => {
if(Me.IsSameConstructAs(block)) {
if(block is IMyShipDrill) {
drills.Add((IMyShipDrill)block);
} else
if(block is IMyConveyorSorter) {
sorters.Add((IMyConveyorSorter)block);
} else
if(block is IMyPistonBase) {
pistons.Add((IMyPistonBase)block);
} else
if(block is IMyShipConnector) {
var connector = (IMyShipConnector)block;
if(connector.ThrowOut) {
ejectors.Add(connector);
} else {
connectors.Add(connector);
}
} else
if(block is IMyRefinery) {
refineries.Add((IMyRefinery)block);
} else
if(block is IMyCargoContainer) {
containers.Add((IMyCargoContainer)block);
} else {
if(block is IMyMotorRotor) {
if(rotor == null) {
rotor = (IMyMotorRotor)block;
} else {
throw new ConstraintException("Structure must include a single rotor");
}
}
}
}
return false;
});
}
Output fragment:
void Init() {
GridTerminalSystem.GetBlocksOfType(dummy, block => {
if(Me.IsSameConstructAs(block)) {
if(block is IMyShipDrill) {
drills.Add((IMyShipDrill)block);
} else
if(block is IMyConveyorSorter) {
sorters.Add((IMyConveyorSorter)block);
} else
if(block is IMyPistonBase) {
pistons.Add((IMyPistonBase)block);
} else
if(block is IMyShipConnector) {
var connector = (IMyShipConnector)block;
if(connector.ThrowOut) {
ejectors.Add(connector);
} else {
connectors.Add(connector);
}
} else
if(block is IMyRefinery) {
refineries.Add((IMyRefinery)block);
} else
if(block is IMyCargoContainer) {
containers.Add((IMyCargoContainer)block);
} else {
if(block is IMyMotorRotor) {
if(rotor == null) {
rotor = (IMyMotorRotor)block;
} else {
throw new ConstraintException("Structure must include a single rotor");
}
}
}
}
return false;
});
}
Preliminary guess is that it's because you're using a nonstandard 2-character indent. I will take a look as soon as I can.
(PS: @ouroborus, you don't need to pass in a dummy list. Just pass in null.)
Oh - another tip. Rather than is -> cast, do
var drill = block as IMyShipDrill;
if (drill != null)
drills.Add(drill);
You'll save a cast.
I just confirmed, by the way, that your issue was caused by your non-standard indentation. I'll see what I can do.
So, after we chatted on Discord, I ran some tests using an added utility class. Here's the test code:
namespace IngameScript {
partial class Program {
public class Class1 {
void Method() {
if(true) {
if(true) {
if(true) {
if(true) {
if(true) {
if(true) {
if(true) {
if(true) {
return;
}
}
}
}
}
}
}
}
}
}
}
}
Tests were run with different indent sizing. The above is the standard 4-space indent.
Results are such that, if I didn't know better, I'd say the rule used is: If a line is indented with less than 8 spaces, leave it alone. Otherwise, trim 8 spaces.
This leaves a situation where, for example, 1-space tabs will seem to trim at a deeper level. As well, odd-number-spaced tabs (3-space, etc.) will still trim 8 spaces, leaving at least one space at the beginning of the line. Ridiculous indents, such as 10-space also still trim 8 spaces. (For example, public class Class1 would be 2 indents deep. With 10-space indents, it would start with 20 leading spaces. The output trims 8 spaces, leaving it with 12 leading spaces.)