It knows only how many global variables there are, so if there's let's say 128 global variables and the flags start at global 111, you know for a fact any flag number divided by 16, plus 111, cannot result in a number higher than 128. So flag 12 is fine (12/16=0), flag 73 is fine (73/16=4, 4+111=115), flag 99 is fine (99/16=6, 6+111=117). Flag 420 is out of bounds (420/16=26, 26+111=137) because we know there's only 128 globals (this is defined by the heap part of script 0). But neither the game nor ScummVM can tell how far the flags go (though lastFlag could help here, it doesn't really need to for the programmer's sake because of the defined flag names), so it's perfectly allowed to play LSL3, set flag 128, and find your character's name is altered.