SRL Archive - OSR Help

Calling function - problem


bg5

2012-01-26 08:44:39

program Test;

function RRandom : TPointArray;
var
a ,b :integer;
begin
b:=2;
setlength(Result,b);
for a:=0 to b-1 do
begin
Result[a].x:=random(100);
Result[a].y:=random(100);
end;
end;

function Printer(arr : TPointArray; tries :integer) : Boolean;
var a,b : integer;

begin
for a:=0 to tries do
begin
writeln('--- TRY : ----- ' + inttostr(a));
for b:=0 to High(arr) do
begin
writeln('index '+inttostr(b)+' : '+inttostr(arr[b].x)+' '+inttostr(arr[b].y));
end;
end;

end;

begin
Printer(RRandom,2);
end.

Compiled successfully in 16 ms.
--- TRY : ----- 0
index 0 : 80 75
index 1 : 19 7
--- TRY : ----- 1
index 0 : 80 75
index 1 : 19 7
--- TRY : ----- 2
index 0 : 80 75
index 1 : 19 7
Successfully executed.

I need the way to get other numbers every TRY ,so - to call RRandom inside Printer every loop. But condition: RRandom must be put to Printer as argument. I think I should use CallProc ,but I don't know how to convert it's output to TPA.

Brandon

2012-01-26 10:11:50

Don't understand the question :S

You want to turn a string into a TPA is what ur asking? or vice-versa or what? "Get other numbers" What numbers?

function Printer(arr : TPointArray; tries :integer; Func: String) : Boolean;
begin
CallProc(Func);
end;

bg5

2012-01-26 10:41:26

"Get other numbers" What numbers?

I mean different Tpoints every "try"

--- TRY : ----- 0
index 0 : 80 75
index 1 : 19 7

RRandom returns 2 random TPoints ,so I need to call RRandom again every loop in Printer.

You want to turn a string into a TPA is what ur asking?

Exactly. I saw in WaitfuncEx that convertion:
   
// var Temp : variant
Temp := CallProc(Func, Args); ;
if (not (VarType(Temp) = varString)) then
Temp := ToStr(Temp);
Result := StrToBoolDef(Temp, False);

So I need to do the same, but with TPA as Result ,or find another way to call function inside other function.

bg5

2012-01-29 08:28:46

bump ?

Brandon

2012-01-29 12:05:30

From: 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:

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 :)

bg5

2012-01-30 07:59:22

Wow ,really thanks for the afford you put into this function. I will test it soon!