SRL Archive - OSR Help

String removal


P1ng

2012-08-27 11:45:59

So I want to search through my inventory and whenever I find an item I want to move the mouse to it and check it's uptext.

Then with that uptext I want to remove the excess bits and pieces like "Fill" and "/ 5 more options" and then just return "Medium pouch" as the result.

Not sure if this is do-able, I have looked through the text include and didn't see anything I thought would help my cause.

Here is the function, it currently finds the objects in the inventory then gets the uptext appropriately, just doesn't remove all the extra little bits as I'd like it to.

function ObjectDetect: String;
var
i: Integer;
TmpBox: TBox;
BlackTPA: TPointArray;

begin
for i := 1 to 28 do
begin
TmpBox := InvBox(i);
if FindColors(BlackTPA, 131072, TmpBox.x1, TmpBox.y1, TmpBox.x2, TmpBox.y2) then
begin
InvMouse(i, mouse_Move);
Wait(RandomRange(400,500));

Result := GetUpText;
WriteLn(Result);
end;
end;
end;

CephaXz

2012-08-27 11:49:13

Maybe you can search for the text with different colors. Items have different colors.

P1ng

2012-08-27 11:51:44

How do you mean, as in only return the string that is written in orange font as opposed to the white terms surrounding it?

Because I want this to be able to check any items in the inventory and give them each a name, which will eventually result in a function that stores the position of that item for later use.

CephaXz

2012-08-27 11:55:03

Oh well, I thought you only want to get medium pouch text since it has orange colors, but other items have different colors. Let me see if I can think of a way to filter out only white color text with the text function.

EDIT: Don't know how to do it in a simple way lol, only had a very complicated idea in mind. Probably some experts can come out with an easy way.

Le Jingle

2012-08-27 12:07:06

I'd check out Jani's string commands link in my siggy ^.^ Can definitely do the required text trim/reduct functionality you want, and then some. If you need help choosing, let me know back on here. Also, testing the snippets out helps give a better idea of what each of the sting commands do.

Edit: Nice 666 post count

P1ng

2012-08-27 12:30:03

Thanks so much for the link LJ! :)

I've got it returning correctly (sort of) using those string handling commands.
However, in a string like 'Fill Large pouch / 5 more options' I can do a before command with the / and that removes all the gear after it. Then I can do an after function to remove everything after 'Fill' but what do I do when that Fill becomes say 'Deposit'? How can I make it remove absolutely any text that may be before it?

E: Using a space ' ' appears to be working for the moment :) Thanks so much!

E2: I thought I was using this all apropriately, but I am getting an empty string array :(
program new;
{$DEFINE SMART}
{$i SRL/SRL.Simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True;
end;
end;

procedure SetupLogin;
begin
ClearDebug;
{$IFDEF SMART}
SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}

SetupSRL;
DeclarePlayers;

ActivateClient;
if not LoggedIn then
LoginPlayer;
end;

function After(s, str: string): string;
var
p, strL, sL: Integer;
begin
sL := Length(s);
strL := Length(str);
if (sL >= strL) then
Exit;
p := Pos(s, str);
if (p > 0) then
Result := Copy(str, (p + sL), ((1 + strL) - (p + sL)));
end;

function Before(s, str: string): string;
var
p: Integer;
begin
if (Length(s) >= Length(str)) then
Exit;
p := Pos(s, str);
if (p > 1) then
Result := Copy(str, 1, (p - 1));
end;

function ObjectDetect: TStringArray;
var
i: Integer;
TmpBox: TBox;
BlackTPA: TPointArray;
begin
SetLength(Result, 29);

for i := 1 to 28 do
begin
TmpBox := InvBox(i);
if FindColors(BlackTPA, 131072, TmpBox.x1, TmpBox.y1, TmpBox.x2, TmpBox.y2) then
begin
InvMouse(i, mouse_Move);
Wait(RandomRange(400,500));
WriteLn(GetUpText);
Result[i] := After(GetUpText, ' ');
Result[i] := Before(Result[i], '/');
end;
end;
end;

begin
SetupLogin;
WriteLn(ObjectDetect);
end.

Le Jingle

2012-08-27 12:39:17

^.^ Glad the link helped. Credit apropos to Janilabo. Those string commands are amazing right?! :D

P1ng

2012-08-27 12:40:24

Check out my edit :( Give the script a run with any items in your inventory, in theory it should return an array of each of those different items names.

masterBB

2012-08-27 12:52:10

Are you able to get a TPointArray with the colors of the uptext? Split it into chars like this:

atpa := SplitTPAEx(tpa, 1, 6);

sort it from the first left up:

SortATPAFromFirstPointx(atpa , Point(0, 0));

Get your text as a string

GetTextATPA(atpa , 4, 'UpChars'{Ex}); //4 - 6, maybe you should try 5

Janilabo

2012-08-27 12:55:26

{$DEFINE SMART}
{$i SRL/SRL.Simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True;
end;
end;

procedure SetupLogin;
begin
ClearDebug;
{$IFDEF SMART}
SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}

SetupSRL;
DeclarePlayers;

ActivateClient;
if not LoggedIn then
LoginPlayer;
end;

function After(s, str: string): string;
var
p, strL, sL: Integer;
begin
sL := Length(s);
strL := Length(str);
if (sL >= strL) then
Exit;
p := Pos(s, str);
if (p > 0) then
Result := Copy(str, (p + sL), ((1 + strL) - (p + sL)));
end;

function Before(s, str: string): string;
var
p: Integer;
begin
if (Length(s) >= Length(str)) then
Exit;
p := Pos(s, str);
if (p > 1) then
Result := Copy(str, 1, (p - 1));
end;

function ObjectDetect: TStringArray;
var
i: Integer;
TmpBox: TBox;
BlackTPA: TPointArray;
begin
SetLength(Result, 29);

for i := 1 to 28 do
begin
TmpBox := InvBox(i);
if FindColors(BlackTPA, 131072, TmpBox.x1, TmpBox.y1, TmpBox.x2, TmpBox.y2) then
begin
InvMouse(i, mouse_Move);
Wait(RandomRange(400,500));
WriteLn(GetUpText);
Result[i] := After(' ', GetUpText);
Result[i] := Before(' /', Result[i]);
end;
end;
end;

begin
SetupLogin;
WriteLn(ObjectDetect);
end.

Runaway

2012-08-27 12:58:39

This is what I've used in a similar situation, perhaps you'll find it useful:


Common := ['Use', 'Wear', 'Wield', 'Craft', 'Eat', 'Drink', 'Fill', 'Withdraw-1', 'Deposit'];
hCommon := High(Common);

Text := GetUpText;
for i := 0 to hCommon do
begin
if (Pos(Common[i], Text) <> 0) then
begin
Found := i;
Break;
end;
end;

Name := Between(Common[Found]+ ' ', ' /', Text);

P1ng

2012-08-27 13:03:18

Thank-you so much Janilabo :)
You are some sort of wizard with words (or strings as it were..)!

It seems to be working perfectly now for me.

E: Thank-you to everyone for their suggestions, advice and input, I'm certain they will all come in handy in the future :)

Janilabo

2012-08-27 13:06:45

You welcome P1ng.. :)
Simple Between(' ', ' /', GetUpText) will work instead of that After+Begin combination, btw.
(Between is already in Simba)

Although, I say check out Runaway's solution.. :p I would go with it.

-Jani