Nice you not simply copy it... Its cool if a user also think about it.
1. Here you must think in correct way.... "$" in a Input Config Formula is related to the "current" Value of the Offset.... So the value BEFORE the input happen.
Technical if you press a Input Button then Mobiflight make a single READ at first and request in FSUIPC the current Value of the Offset we like to write.
Then it set this readed value as a temporary Variable "$" .
As a guy with some programming skills you know.... There exist not only one correct formula..... There exist thousend. And all will work. Question is only what formula is more profitable and efficient.
For example:
Lets say a toggle 0,1,2,3 like you explane with a backstep from 3 to 0.
We can say.... if($=3,0,$+1) ..... We can also say .... if($>2,0,$+1) .... Or.... if($+1=4,0,$+1) .....
And finaly the most smart solution is ($+1)%4 Here we save the If condition and multiple internal steps.... This is just poor math.
If Value is currently "1" we say 1+1=2 And then 2 %MODULO 4 and that result in "2" . The swap Point.... If Value is currently "3" ... 3+1=4 4%4=0
****
2. Unticking Output Lines is not a "normal" procedure. Specialy if MF is still running this is not working correct.... Means a LED e.g. still light whatever Line is unticked. Simply cause it is no longer controlled but still on. Same if you activate a Config while MF is running. Then the Device get not "updated" until you send a new value or open the Config by hand ( what also internal execute a short Rfresh to it) .
So.... Please see the Option " Enable/Disable" Config by checkmark as a tool that should be used only in STOP mode and also only in special situations. I will say a "normal" user will never need to use those checkmarks.... Only advanced Users in special projects.
3. Mobiflight itself have no "memory" and technical also no global Variables.....
The "Offset" are a Part of FSUIPC.
So FSUIPC read a verry large raw Datastring from the Sim ( by simconnect) and order it to the "Offsets" . Mobiflight itself talk to FSUIPC. If you create e.g. a Output Config then Mobiflight simply read multiple times per second the specific Area of the FSUIPC data ( adressed via the Offset Number) .
If you like to know more.... You can download the full Mobiflight Code on Bitbucket.
https://bitbucket.org/mobiflight/mobiflightfc/src/master/