SRL Archive - OSR Help

Help getting the GE price!


logical

2011-12-19 10:46:02

program GEDB;
{$i SRL\SRL.scar}

function GetPrice(itemID: Integer): Integer;
var
price, page, itemName: String;
tm, div_, xer_: Integer;
begin
MarkTime(tm);

Page := GetPage('http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj=' + IntToStr(itemID));
Price := Between('<td>',' </td>', Page);
ItemName := Between('<title>',' - Grand Exchange - RuneScape</title>', Page);
Price := ReplaceWrap(Price, ',', ' ', [rfReplaceAll]);

if (Price <> '') then
begin
if ( Length(Price) > Length(ReplaceWrap(Price, '.', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, '.', '', [rfReplaceAll]);
div_ := 10;
end;

if ( Length(Price) > Length(ReplaceWrap(Price, 'k', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, 'k', '', [rfReplaceAll])
WriteLn('"k" was found in the item price');
xer_ := 1000;
end else if ( Length(Price) > Length(ReplaceWrap(Price, 'm', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, 'm', '', [rfReplaceAll])
WriteLn('"m" was found in the item price');
xer_ := 1000000;
end else if ( Length(Price) > Length(ReplaceWrap(Price, 'b', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, 'b', '', [rfReplaceAll])
WriteLn('"b" was found in the item price');
xer_ := 1000000000;
end;
WriteLn(price);
Result := (StrToInt(Price) * xer_) / div_;
WriteLn('The price of item ' + ItemName + ' is ' + IntToStr(Result) + 'gp');
end else begin
WriteLn('The price of the item was invalid');
Result := (-1);
end;

WriteLn('This took ' + ToStr(TimeFromMark(tm)/1000.0) + ' seconds');

end;


begin
ClearDebug;
GetPrice(1038); //red partyhat
end.

OK so this to me looks like its meant to work but it returns a very wrong price.

"b" was found in the item price
14
The price of item Red partyhat is 111509811gp
This took 1.529 seconds
Successfully executed.

so i get the number 14 for its price before i turn it into an integer thats fine

but after i change it, multiply it by 1,000,000,000 and divide it by 10 it comes up with 111509811…!?!?…how does that work?
:thumbsdown: :unsure:

Floor66

2011-12-19 11:09:36

Integers only go so far iirc. Why not just append a string of '000,000,000' to the integer.

Kyle Undefined

2011-12-19 11:10:05

Have you tried this?

 Result := ((StrToInt(Price) * xer_) / div_);

And is the "div_" var being set?

logical

2011-12-19 11:11:52

umm i'm not sure what floor66's means but in response to kyle…it was set on line 42

E: oo i think i get what floor means…lemme try an do that then :D

E2: nope…still stuck…i dont think i can use xer_ (meaning multiplier) as a string as then the result it returns wont be correct..

Kyle Undefined

2011-12-19 12:53:30

Try this:


program GEDB;
{$i SRL\SRL.scar}

function GetPrice(itemID: Integer): Extended;
var
price, page, itemName: String;
tm, div_, xer_: LongInt;
res : Extended;
begin
MarkTime(tm);

Page := GetPage('http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj=' + IntToStr(itemID));
Price := Between('<td>',' </td>', Page);
ItemName := Between('<title>',' - Grand Exchange - RuneScape</title>', Page);
Price := ReplaceWrap(Price, ',', ' ', [rfReplaceAll]);

if (Price <> '') then
begin
if ( Length(Price) > Length(ReplaceWrap(Price, '.', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, '.', '', [rfReplaceAll]);
div_ := 10;
end;

if ( Length(Price) > Length(ReplaceWrap(Price, 'k', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, 'k', '', [rfReplaceAll])
WriteLn('"k" was found in the item price');
xer_ := 1000;
end else if ( Length(Price) > Length(ReplaceWrap(Price, 'm', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, 'm', '', [rfReplaceAll])
WriteLn('"m" was found in the item price');
xer_ := 1000000;
end else if ( Length(Price) > Length(ReplaceWrap(Price, 'b', '', [rfReplaceAll])) ) then begin
Price := ReplaceWrap(Price, 'b', '', [rfReplaceAll])
WriteLn('"b" was found in the item price');
xer_ := 1000000000;
end;
WriteLn(price);
res := StrToInt(Price);
res := res * xer_;
res := res / div_;
Result := Int(res);
WriteLn('The price of item ' + ItemName + ' is ' + ToStr(Result) + 'gp');
end else begin
WriteLn('The price of the item was invalid');
Result := (-1);
end;

WriteLn('This took ' + ToStr(TimeFromMark(tm)/1000.0) + ' seconds');

end;


begin
ClearDebug;
GetPrice(1038); //red partyhat
end.