Results 1 to 6 of 6

Thread: Passing Functions through Functions

  1. #1
    Join Date
    Oct 2010
    Posts
    1,255
    Mentioned
    0 Post(s)
    Quoted
    15 Post(s)

    Default Passing Functions through Functions

    I think I remember seeing something about passing a function through a function using the @ symbol?

    Basically, I run this code block a lot:

    Simba Code:
    Start := GetSystemTime;
        repeat
          Wait(100);
          if((GetSystemTime - Start) > 7500)then
          begin
            Failsafe(False);
            Break;
          end;
        until(not(R_BankScreen))

    So I want to make a function allowing myself to input a value instead of the 7500 for the Breakout time, and then the until() condition.

    But you can't just do WhateverFunction(7500, not(BankScreen)) because that will run the function and actually pass the result through correct?

    Would it be: WhateverFunction(7500, @not(BankScreen)) ?

    Can't test atm, have a sick proggy going.
    I'm back

  2. #2
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    I would say it would be:
    Simba Code:
    WhateverFunction(7500, not(@BankScreen))
    I have never tried it before, theres a tutorial on it thought, can't remember who wrote it.
    There used to be something meaningful here.

  3. #3
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    you might have to do

    Simba Code:
    bool := bankscreen;

    or
    Simba Code:
    if bankscreen then
      bool := true;

    then
    Simba Code:
    whateverfunction(bool)
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  4. #4
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Simba Code:
    function WaitFor(f: function: Boolean; timeout: Integer):Boolean;
    var
      time: Integer;
    begin
      time := GetSystemtime;
      while ((not f) and (time-GetSystemtime > timeout))  do
        wait(16+Random(40));
    end;

    //..
    waitfor(@bankscreen, 2000);

    Pretty sure this is already in SRL too.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  5. #5
    Join Date
    Oct 2010
    Posts
    1,255
    Mentioned
    0 Post(s)
    Quoted
    15 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    you might have to do

    Simba Code:
    bool := bankscreen;


    or Simba Code:
    if bankscreen then
    bool := true;


    then
    Simba Code:
    whateverfunction(bool)
    That's the same as just passing the function as a parameter, which is what I don't want to do.

    I want the function to run inside the main function, not before and pass a value into it.

    Quote Originally Posted by Nava2 View Post
    Simba Code:
    function WaitFor(f: function: Boolean; timeout: Integer):Boolean;
    var
    time: Integer;
    begin
    time := GetSystemtime;
    while ((not f) and (time-GetSystemtime > timeout)) do
    wait(16+Random(40));
    end;

    //..
    waitfor(@bankscreen, 2000);



    Pretty sure this is already in SRL too.

    Exactly. It doesn't show up in the FunctionList and I have SRL included, possibly a misc include?

    Anyways I'll just use my own. Do you happen to know to do it for the reverse condition?

    Just ?:

    waitfor(@(not bankscreen), 2000);
    I'm back

  6. #6
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by smurg View Post
    That's the same as just passing the function as a parameter, which is what I don't want to do.

    I want the function to run inside the main function, not before and pass a value into it.




    Exactly. It doesn't show up in the FunctionList and I have SRL included, possibly a misc include?

    Anyways I'll just use my own. Do you happen to know to do it for the reverse condition?

    Just ?:

    waitfor(@(not bankscreen), 2000);
    No, but its in Timing.scar.

    You can't pass it like that. Look up `procedural functional pointers` in the tutorial island.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

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
  •