Results 1 to 6 of 6

Thread: Calling function - problem

  1. #1
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Exclamation Calling function - problem

    Simba Code:
    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.

    Code:
    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.

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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?
    Code:
    function Printer(arr : TPointArray; tries :integer; Func: String) : Boolean;
    begin
        CallProc(Func);
    end;
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    "Get other numbers" What numbers?
    I mean different Tpoints every "try"

    Code:
    --- 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:
    Simba Code:
    // 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.

  4. #4
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    bump ?

  5. #5
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by beginner5 View Post
    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
    I am Ggzz..
    Hackintosher

  6. #6
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •