From e476e6d60ac91ea615b8d2c8842d7c38e70a1877 Mon Sep 17 00:00:00 2001 From: Max Siyazov Date: Sun, 12 Dec 2021 18:50:57 +0000 Subject: [PATCH] Allow #comment lines in macros. Updated the Macros documentation. --- docs/Macros.md | 24 ++++++++++++++++++++++++ nxbt/controller/input.py | 1 + 2 files changed, 25 insertions(+) diff --git a/docs/Macros.md b/docs/Macros.md index 2484d7b..3604f5c 100644 --- a/docs/Macros.md +++ b/docs/Macros.md @@ -43,6 +43,30 @@ L_STICK@+000+000 0.75s 1.0s ``` +### Loops + +A simple for-loop can be used to repeat a macro block a specified number of times. The below example loops through an indented macro block 100 times. + +``` +LOOP 100 + B 0.1s + 0.1s +``` + +Nested loops are also supported. + +``` +LOOP 100 + B 0.1s + 0.1s + # Nested loop + LOOP 5 + A 0.1s + 0.1s +``` + +Note, a macro line starting with `#` is ignored. + ## Macro Control Values | Macro Value | Control Name | diff --git a/nxbt/controller/input.py b/nxbt/controller/input.py index 6b27749..1249f63 100644 --- a/nxbt/controller/input.py +++ b/nxbt/controller/input.py @@ -307,6 +307,7 @@ class InputParser(): parsed = macro.split("\n") parsed = list(filter(lambda s: not s.strip() == "", parsed)) + parsed = list(filter(lambda s: not s.strip().startswith("#"), parsed)) parsed = self.parse_loops(parsed) return parsed