One solution is to use a function.
MAX_TIME() {
return 25
}
MsgBox % MAX_TIME()
Attempting to redefine the function produces Error: Duplicate function definition
.
MAX_TIME() {
return 25
}
MsgBox % MAX_TIME()
MAX_TIME() {
return 22
}
Note that even after the function has been defined, creating a value with MAX_TIME = 20
is still allowed, so be consistent and always use the function instead of a variable.
Two other approaches are described at https://autohotkey.com/board/topic/90774-is-it-possible-to-create-constant/. The first is to simply use a variable and remember not to change it. This seems to be the preferred approach.
The second is to use a class property to store the constant, and override __Set()
so that the value cannot be changed.
Python works pretty much the same way. See How do I create a constant in Python?