Here is a puzzle I can't wrap my head around.
The code below works:
CONST_TIME_SPEED1S = 4000
CONST1_SPEED1S = 0.5
CONST2_SPEED1S = 0.12
CONST3_SPEED1S = 0.1
DS_FLAPS_SLOW = 0
DS_ERROR_F_NO_SPEED = 0
Timer_Speed_1s = 0
Direction = 'DIRECTION_LOWER'
Flag_Flaps_Primary_Fault = 0
def main_logic():
if Direction == 'DIRECTION_LOWER':
if Timer_Speed_1s > CONST_TIME_SPEED1S:
if (Speed1S < CONST1_SPEED1S) and (Speed1S > CONST2_SPEED1S):
DS_FLAPS_SLOW = 1
DS_ERROR_F_NO_SPEED = 0
else:
DS_FLAPS_SLOW = 0
if Speed1S < CONST3_SPEED1S:
DS_ERROR_F_NO_SPEED = 1
DS_FLAPS_PRIMARY_FAULT = 1
else:
DS_ERROR_F_NO_SPEED = 0
if Flag_Flaps_Primary_Fault == 1:
pass
else:
DS_FLAPS_PRIMARY_FAULT = 0
else:
DS_FLAPS_SLOW = 0
DS_ERROR_F_NO_SPEED = 0
else:
Timer_Speed_1S = 0
DS_FLAPS_SLOW = 0
DS_ERROR_F_NO_SPEED = 0
main_logic()
print ('DS_FLAPS_SLOW = ', DS_FLAPS_SLOW)
print ('DS_ERROR_F_NO_SPEED = ', DS_ERROR_F_NO_SPEED)
If I change name of the variable 'Timer_Speed_1s' into 'Timer_Speed_1S', I get a message "UnboundLocalError: local variable 'Timer_Speed_1S' referenced before assignment".
To puzzle me more, when I strip the code down to:
Timer_Speed_1S = 0
def main_logic():
print (Timer_Speed_1S)
main_logic()
everything works just fine, no error messages. How can it be?