From: Element17
That does make sense and I knew that about the "if then" statements, guess I had a brain fart. Also, I thought functions were always set to false so there was no need to set it to false?
It depends.
Sometimes you may have to use "Result := False;" in your functions, depends what kind of functions you write, though.
But yeah, most of the time it is a good habbit!
Small examples:
var
monsterExists, loggedIn: Boolean;
function FindMonster: Boolean;
begin
if loggedIn then
Result := True;
end;
begin
loggedIn := True;
monsterExists := FindMonster;
WriteLn(monsterExists);
loggedIn := False;
monsterExists := FindMonster;
WriteLn(monsterExists);
end.
Debugs:
Compiled successfully in 31 ms.
True
True
Successfully executed.
..whereas…
var
monsterExists, loggedIn: Boolean;
function FindMonster: Boolean;
begin
Result := False;
if loggedIn then
Result := True;
end;
begin
loggedIn := True;
monsterExists := FindMonster;
WriteLn(monsterExists);
loggedIn := False;
monsterExists := FindMonster;
WriteLn(monsterExists);
end.
Debugs:
Compiled successfully in 31 ms.
True
False
Successfully executed.
So there you can see the difference.. :)
-Jani