Quite frequently the old-school flag gets jammed at an unreachable location, causing functions like FFlag() and common loops like "while FlagPresent do wait(100)" to cause issues in scripts.
This function can be used in place of both previously mentioned flag techniques. This function returns true and ends if FlagDistance doesn't change for "maxtime", with a wait of "poll" between measurements. But if the flag doesn't jam, it acts like FFlag and waits until FlagDistance is less than or equal to "FlagDist".
Simba Code:
function NebulaFlag(FlagDist, Maxtime, Poll: Integer): boolean;
var
tt, q, f: Integer;
FlagArr: Array of Integer;
flagGood: boolean;
Label
reset;
begin
tt:= maxtime;
marktime(q);
while (FlagDistance > FlagDist) do
begin
FindNormalRandoms;
SetLength(FlagArr, Length(FlagArr)+1);
FlagArr[High(FlagArr)] := Flagdistance;
if (TimeFromMark(q) > tt) then
begin
for f:= High(FlagArr) downto (High(FlagArr) - round(maxtime/poll)) do
begin
if FlagArr[max(0, f)] <> FlagArr[max(0, f-1)] then
begin
flagGood := true;
break;
end;
end;
if flagGood then
GoTo reset;
writeln('flag jammed');
result := true;
Exit;
end;
reset:
wait(poll);
end;
end;