
Originally Posted by
beginner5
bump ?
Kk so I hope everyone appreciates the work I put into this function as I had to write it in C++ first then translate to pascal as I'm not as good in Pascal as I am in C++
This will 100% do the trick:
Simba Code:
program StrToTPA;
{$I SRL/SRL.Simba}
Function StringToTPA(TPA: String): TPointArray;
var
I, J, X, Y: Integer;
Str: String;
TempTPA: TPointArray;
begin
if (ExecRegExpr('^\[\([0-9]*,(\s*|^\s)[0-9]*\)*', TPA) and ExecRegExpr('\)\]$', TPA)) then
begin
if (Not ExecRegExpr('~|!|@|#|\$|%|\^|&|\*|_|\+|=|{|}|"|''|:|;|\.|<|>|\?|/|[a-z]|[A-Z]|(\[-|-\(|\)-|\),-|-\])|\\|\.|(\((\s*|^\s)\()|(,(\s*|^\s),)|(\)(\s*|^\s)\))', TPA)) then
begin
writeln('TPA String is a Valid TPointArray Match.');
For I:= 1 To High(TPA) do
begin
if (TPA[I] = '(') then
begin
Inc(I);
while (ExecRegExpr('[0-9]', TPA[I])) do //beginning of a point..
begin
str:= str + TPA[I];
Inc(I);
if (TPA[I] = ',') then
begin
X:= StrToInt(str);
str:= '';
break;
end;
end;
end;
if (TPA[I] = ',') then
begin
I:= I + 2; //Because there is a space..
while (ExecRegExpr('[0-9]', TPA[I])) do
begin
str:= str + TPA[I];
Inc(I);
if (TPA[I] = ')') then
begin
Y:= StrToInt(str);
str:= '';
break;
end;
end;
I:= I - 1; //I Must be reset or else X will stay the same as the first iteration..
end;
if (TPA[I] = ')') then
begin
SetLength(TempTPA, Length(TempTPA) + 1);
TempTPA[J]:= Point(X, Y);
Inc(J);
SetLength(Result, Length(TempTPA));
Result:= TempTPA;
end;
end;
end else
begin
writeln('Invalid String To TPointArray Match!');
SetLength(Result, 1);
Result[0]:= Point(-99999, -99999);
end;
end else
begin
writeln('Invalid String To TPointArray Match!');
SetLength(Result, 1);
Result[0]:= Point(-99999, -99999);
end;
end;
Var
TPA: TPointArray;
begin
ClearDebug;
TPA:= StringToTPA('[(10, 10), (9, 5), (6, 87), (300, 190), (4, 270), (934, 5345)]');
MouseSpeed:= 8; //Not really needed but I'm too lazy to wait on the mouse to finish moving..
MMouse(TPA[0].X, TPA[0].Y, 0, 0);
end.
For anyone wanting a brief explanation.. well that's not possible.. as if I were to explain, you'd need to have an extremely strong understanding of a RegEx aka RegExpressions to understand the explanation.. If you do then comment and I'll break down the code as best as I can.. Yes.. I wrote that expression from scratch just to answer his question.. -__-
GoodLuck