Results 1 to 7 of 7

Thread: HWait; need to get fixed! thanks!

  1. #1
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default HWait; need to get fixed! thanks!

    hey,

    i want it to do what there stand if you put in somthing like:
    BankScreen, InFight
    in the HUntil

    HWait:
    SCAR Code:
    Function HWait (MaxTime:Integer; HUntil:Boolean): Boolean;
    Var
      Time : Integer;
    Begin
      MarkTime(Time);
      Repeat
        Wait(100 + Random(50));
      Until HUntil or (TimeFromMark(Time) > MaxTime);
    End;

    edit:
    SCAR Code:
    HWait(5000,BankScreen);
    HWait(5000,InFight);

    // this would be very handy!!!
    ~Hermen

  2. #2
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Function senders ftw! (here)
    It won't work by just putting something into it as it only evaluates it at the start of the function/procedure, so it will either return true or false (if it outputs a boolean) for the entire running of the procedure. The function sender tells it to run the function everytime. Though I must warn you - you have to make a procedure with just bankscreen or infight in it and set it up as according to the function sender tut otherwise it won't work.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  3. #3
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I JUST WANT THIS WORKING!!!! grrrrrrr!!!(not blaming one of you!!!)

    I JUST WANNA USE THIS FOR EVERYTHING I INPUT!!!!
    ~Hermen

  4. #4
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Ahh, I started one before you posted this, and posted it in your other thread...
    Here you go:
    SCAR Code:
    program New;

    function Bool: Boolean;
    begin
      Result:= Random(100) = 0;
    end;

    procedure HWait(MaxTime: Integer; HUntil: Function: Boolean);
    var
      T: Integer;
    begin
      T:= GetSystemTime;
      while not HUntil() and not(GetSystemTime - T > MaxTime) do
        wait(50);
    end;

    begin
      HWait(5000, @Bool);
    end.

  5. #5
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i'm sorry that's not what i mean, i will explain an example in first post
    ~Hermen

  6. #6
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    That's what I made.
    HWait(5000, @BankScreen);

    EDIT: Also made it work with arrays of functions
    SCAR Code:
    program New;
    type
      TFunctionArray = Array of Function: Boolean;
    var
      Functions: TFunctionArray;

    function Bool: Boolean;
    begin
      Result:= Random(100) = 0;
    end;

    procedure HWait(MaxTime: Integer; HUntil: Function: Boolean);
    var
      T: Integer;
    begin
      T:= GetSystemTime;
      while not HUntil() and not(GetSystemTime - T > MaxTime) do
        wait(50);
    end;

    procedure HWaitMulti(MaxTime: Integer; HUntil: TFunctionArray);
    var
      T, I: Integer;
    begin
      T:= GetSystemTime;
      repeat
        for I:= 0 to High(HUntil) do
          if(HUntil[I]())then exit;
        wait(50);
      until(GetSystemTime - T > MaxTime)
    end;

    begin
      SetLength(Functions, 1);
      Functions[0]:= @Bool;
      HWaitMulti(5000, Functions);
    end.

  7. #7
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ow awsome! thanks!
    ~Hermen

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
  •