If you use nested M291 commands with a messagebox mode S4... S7 (the ones that create an "input" variable), the last message box overwrites the initial one, which may result in the wrong initial task being executed:
Here is a quick example. If you choose "load filament into left hotend" which is the first option in the initial message box (--> input = 0) and then choose the option not to wipe or clean the hotend nozzles, then the input variable changes to 2 which causes the option "load filament for both hotends" of the initial message box to be executed.
M291 S4 K{"left","right","both","back"} P"Please choose the hotend to load" R"load filament"
if input = 0
; do stuff...
M291 S4 K{"wipe","manual clean","done"} P"Wipe or clean the hotend nozzle?" R"load filament - left"
if input = 0
; wipe and finish
if input = 1
; move to a convenient cleaning position and request cleaning
if input = 2
break ; finish
if input = 1
; do stuff...
M291 S4 K{"wipe","manual clean","done"} P"Wipe or clean the hotend nozzle?" R"load filament - right"
if input = 0
; wipe and finish
if input = 1
; move to a convenient cleaning position and request cleaning
if input = 2
break ; finish
if input = 2
; do stuff...
M291 S4 K{"wipe","manual clean","done"} P"Wipe or clean the hotend nozzles?" R"load filament - both"
if input = 0
; wipe and finish
if input = 1
; move to a convenient cleaning position and request cleaning
if input = 2
break ; finish
if input = 3
; finish
This behaviour is logical if you keep in mind that the message boxes fill the variable "input" which only exists once per macro, in opposite to the "iterations" loop counter.
But since I did not think this through and kept searching for some typo for days until the penny dropped , I hereby vote to add a corresponding remark to the notes of M291 in the Gcode dictionary - something like this maybe: " NOTE: If you use more than one message box with mode S4... S7 within the the same macro, keep in mind that the same input variable is used for all message boxes, which means it only shows the input from the last message box."