SRL Archive - OSR Help

Invalid integer :(


GREEN GIANT

2013-08-26 13:34:48

Hey guys,

Quick question, if i get serious lag or a delay in the script it fails on the following line;

Until (StrToInt(NatureRuneCount) <= 0) or (TimeFromMark(T) > 25000);

With the following error;

Error: Exception: "" is an invalid integer at line 305

(StrToInt(NatureRuneCount) //counts amount of Nats using TPAs.

Now it runs fine most of the time, but like i mentioned above if there is lag it fails, im assuming because NatureRuneCount does not have a valid value.

Is there a way to stop this?

Sin

2013-08-26 13:40:21

Nature Rune Count is returning a string with characters in it.
Do writeln(NatureRuneCount); before the until and post the results please.

Also, this line:
Until (StrToInt(NatureRuneCount) <= 0) or (TimeFromMark(T) > 25000);
Are you expecting the NatureRuneCount to go into the negatives?

GREEN GIANT

2013-08-26 14:05:19

From: Sin
Nature Rune Count is returning a string with characters in it.
Do writeln(NatureRuneCount); before the until and post the results please.

Also, this line:
Until (StrToInt(NatureRuneCount) <= 0) or (TimeFromMark(T) > 25000);
Are you expecting the NatureRuneCount to go into the negatives?


It's just returning the amount of natures left (as it should) As i said it works fine usually but if there is lag and it skips it fails at that line. As for the <=0 bit, it used to be a higher number (1) when i changed it to 0 i didn't bother changing the <= as it shouldn't make a difference :p

This is the code i used if you're interested:


Function CosmicRuneCount: String;
var x, y: integer;
ATPA: T2DPointArray;
TPA : TPointArray;
begin
if FindColorsSpiralTolerance(x, y, TPA, 65535, 124, 114, 150, 127, 0) then
begin
ATPA := splitTPAEx(TPA, 1, 1);
sortATPAFromFirstPointX(ATPA, point(0, 0));
//DebugATPABounds(ATPA);
Result := (gettextatpa(ATPA, 10, 'statchars07'));
end;
end;

bgtemp

2013-08-26 14:41:50

As Sin said this error happens when you load in StrToInt() string, which is not exaclty a number. It might be either emtpy string or some additional non-numeral characters. So when OCR fails propably due to lag you get this exeption. To get rid of this you shout check if NatureRuneCount is proper string (number) before using StrToInt().

GREEN GIANT

2013-08-26 14:46:06

From: bgtemp
As Sin said this error happens when you load in StrToInt() string, which is not exaclty a number. It might be either emtpy string or some additional non-numeral characters. So when OCR fails propably due to lag you get this exeption. To get rid of this you shout check if NatureRuneCount is proper string (number) before using StrToInt().


Well the function GetTextATPA returns a string, so i naturally assumed i would need to use StrToInt, i'll have a play around and see if i can force it to fail again and see what crops up.

Brandon

2013-08-26 18:04:40

From: GREEN GIANT
Well the function GetTextATPA returns a string, so i naturally assumed i would need to use StrToInt, i'll have a play around and see if i can force it to fail again and see what crops up.


Use StrToIntDef.. And give it a default value if it fails.. Can also use "ExtractNumbers" or whatever that function is that extracts numbers from a string. Should help ease the pain a bit I guess.

bgtemp

2013-08-26 19:45:30

I think if OCR found non-numeric characters in the place where they are not supposed to be, you shouldn't extract anything from this string as it will be wrong anyway. I would suggest to throw it out and read text again.

I've rebuilt your function a bit. I can't test it but hope it's work. Notice it returns integer now.


Function CosmicRuneCount: integer;
var x, y, i ,HowManyTries: integer;
s : string;
ATPA: T2DPointArray;
TPA : TPointArray;
begin
HowManyTries := 3;
for i:= 1 to HowManyTries do
begin
if FindColorsSpiralTolerance(x, y, TPA, 65535, 124, 114, 150, 127, 0) then
begin
ATPA := splitTPAEx(TPA, 1, 1);
sortATPAFromFirstPointX(ATPA, point(0, 0));
//DebugATPABounds(ATPA);
s := (gettextatpa(ATPA, 10, 'statchars07'));

if not(ExecRegExpr('[^0-9]',s)or(High(s)<1)) then // checking if string is wrong or empty
begin
Result := StrToInt(s);
exit;
end;

end;
writeln('Failed to get rune count, trying again... '+tostr(i));
wait(300); // little delay
end;

writeln('RuneCount: Failed');
Result := -1;
end;

GREEN GIANT

2013-08-27 14:04:02

From: bgtemp
I think if OCR found non-numeric characters in the place where they are not supposed to be, you shouldn't extract anything from this string as it will be wrong anyway. I would suggest to throw it out and read text again.

I've rebuilt your function a bit. I can't test it but hope it's work. Notice it returns integer now.




Function CosmicRuneCount: integer;
var x, y, i ,HowManyTries: integer;
s : string;
ATPA: T2DPointArray;
TPA : TPointArray;
begin
HowManyTries := 3;
for i:= 1 to HowManyTries do
begin
if FindColorsSpiralTolerance(x, y, TPA, 65535, 124, 114, 150, 127, 0) then
begin
ATPA := splitTPAEx(TPA, 1, 1);
sortATPAFromFirstPointX(ATPA, point(0, 0));
//DebugATPABounds(ATPA);
s := (gettextatpa(ATPA, 10, 'statchars07'));

if not(ExecRegExpr('[^0-9]',s)or(High(s)<1)) then // checking if string is wrong or empty
begin
Result := StrToInt(s);
exit;
end;

end;
writeln('Failed to get rune count, trying again... '+tostr(i));
wait(300); // little delay
end;

writeln('RuneCount: Failed');
Result := -1;
end;


The above works a dream , tested it a little and returns accurately so thankyou :)

GREEN GIANT

2013-08-27 14:06:49

From: Brandon
Use StrToIntDef.. And give it a default value if it fails.. Can also use "ExtractNumbers" or whatever that function is that extracts numbers from a string. Should help ease the pain a bit I guess.


I was actually looking at this before 'bgtemp' posted me a very nice alternative, but thanks :)