SRL Archive - OSR Help

Really odd, function returning string only works for 1 if statement


rj

2013-06-21 23:15:35

So I have a function that gets the players position:

function GetMyPos():string;
begin
if FindIconDist(7394286, 13, 15, 0.03, 0.88) and FindIconDist(3174424, 8, 60, 0.20, 2.20) then
begin
result := 'bank';
exit;
end;
if (FindIconDist(8602720, 6, 25, 0.06, 0.41) and FindIconDist(16206088, 6, 27, 0.12, 0.02)) then
begin
result := 'Stone';
exit;
end;
if (FindIconDist(229374, 3, 25, 2.11, 0.42) and seeWater) then
begin
result := 'Alter';
exit;
end else
Result := 'Unknown';
end;

(takes 16 ms and works fine tyvm)

And to find out were I am I do:

Writeln(GetMyPos);

And it outputs the correct spot

BUT When ever I try to do this:

if (GetMyPos = 'Alter') then secretprocedure;
if (GetMyPos = 'Bank') then LocateBank;

If im at the alter it will do secret procedure, but if i'm at the bank it won't do locatebank (and yes it can find the bank)

Any reason why I can't use the function returning a string for more then 1 if statements? Do I have to use a global variable?

Sin

2013-06-21 23:17:12

Remove the 'end else Result := 'Unknown';' and move Result := 'Unknown'; to the beginning of the function.

rj

2013-06-21 23:19:23

From: Sin
Remove the 'end else Result := 'Unknown';' and move Result := 'Unknown'; to the beginning of the function.


Done, problem still persists (or was that a tip?)

Justin

2013-06-21 23:20:33

From: Officer Barbrady
So I have a function that gets the players position:

function GetMyPos():string;
begin
if FindIconDist(7394286, 13, 15, 0.03, 0.88) and FindIconDist(3174424, 8, 60, 0.20, 2.20) then
begin
result := 'bank';
exit;
end;
if (FindIconDist(8602720, 6, 25, 0.06, 0.41) and FindIconDist(16206088, 6, 27, 0.12, 0.02)) then
begin
result := 'Stone';
exit;
end;
if (FindIconDist(229374, 3, 25, 2.11, 0.42) and seeWater) then
begin
result := 'Alter';
exit;
end else
Result := 'Unknown';
end;

(takes 16 ms and works fine tyvm)

And to find out were I am I do:

Writeln(GetMyPos);

And it outputs the correct spot

BUT When ever I try to do this:

if (GetMyPos = 'Alter') then secretprocedure;
if (GetMyPos = 'Bank') then LocateBank;

If im at the alter it will do secret procedure, but if i'm at the bank it won't do locatebank (and yes it can find the bank)

Any reason why I can't use the function returning a string for more then 1 if statements? Do I have to use a global variable?


Also "Bank != bank"

use (LowerCase(GetMyPos) = 'alter') ect

Sin

2013-06-21 23:21:08

Bank is capitalised.

rj

2013-06-21 23:25:16

From: Justin
Also "Bank != bank"

use (LowerCase(GetMyPos) = 'alter') ect


Ahh gotcha. I thought pascal wasn't case sensitive (I guess thats just vars and procedures/functions?)

It was my fault for having inconsistent practices anyway

Brandon

2013-06-22 00:01:00

From: Officer Barbrady
Ahh gotcha. I thought pascal wasn't case sensitive (I guess thats just vars and procedures/functions?)

It was my fault for having inconsistent practices anyway



Literals in no language is case insensitive. Keywords would be case insensitive in some languages but never literals.

Literals include bytes/chars, strings, array of chars, char*, const char*, array of strings, etc..


Why? Because ASCII.. that's why:

A = 0x41 || 1000001
a = 0x61 || 1100001


Both completely different values. Notice that 1 bit that's changed? That's how you convert from upper to lowercase. Register sees that 1 bit set, it knows it's lowercase.

Sin

2013-06-22 00:04:18

From: Brandon
Literals in no language is case insensitive. Keywords would be case insensitive in some languages but never literals.

Literals include bytes/chars, strings, array of chars, char*, const char*, array of strings, etc..


Why? Because ASCII.. that's why:

A = 0x41 || 1000001
a = 0x61 || 1100001


Both completely different values. Notice that 1 bit that's changed? That's how you convert from upper to lowercase. Register sees that 1 bit set, it knows it's lowercase.


And that's why .equalsIgnoreCase() is my best friend :)