SRL Archive - OSR Help

Not sure if this is working


Element17

2013-07-04 01:20:28


function CheckLocation: Boolean;
var
P: TPoint;
begin
P := SPS_GetMyPos;
if (p.x = - 1) and (p.y = - 1) then
writeln('SPS Position is returning -1, -1...');
Result := true;
Exit;
end;

Does not seem to work. I try it in the correct location as well as where sps would return -1, -1.

I use it like

 if (CheckLocation) then
logout;
terminatescript;
blah blah

It always logout no matter where I am even if in the correct position.

bolshak25

2013-07-04 01:34:47

From: Element17

function CheckLocation: Boolean;
var
P: TPoint;
begin
P := SPS_GetMyPos;
if (p.x = - 1) and (p.y = - 1) then
writeln('SPS Position is returning -1, -1...');
Result := true;
Exit;
end;

Does not seem to work. I try it in the correct location as well as where sps would return -1, -1.

I use it like

 if (CheckLocation) then
logout;
terminatescript;
blah blah

It always logout no matter where I am even if in the correct position.



function CheckLocation: Boolean;
var
P: TPoint;
begin
P := SPS_GetMyPos;
Result := False;
if (p.x = - 1) and (p.y = - 1) then
begin
writeln('SPS Position is returning -1, -1...');
Result := true;
end;
Exit;
end;

if (CheckLocation) then
begin
logout;
terminatescript;
end;
blah blah

when you use if … then and you want it to do multiple things such as what youre doing, then you need the begin and end to tell it what all to do. if you just want to do that next line, then you dont need the begin and end

it probably wont format properly, but i hope this helps explanation wise

also, i added the result is false in the first one, that way if it does give you -1 -1 then itll change it to true and logout, but if it doesnt, then itll leave it as false

Element17

2013-07-04 10:24:57

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?

Rich

2013-07-04 13:56:03

From: Element17
Also, I thought functions were always set to false so there was no need to set it to false?
All booleans are false by default, so you're right, there is no need to declare them as false at the start.

Janilabo

2013-07-04 15:02:12

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

Element17

2013-07-04 21:59:47

Ahhh I see! Well thank you for that! +Rep