Results 1 to 5 of 5

Thread: What's a callback function?

  1. #1
    Join Date
    Oct 2015
    Location
    Nowhere
    Posts
    134
    Mentioned
    2 Post(s)
    Quoted
    64 Post(s)

    Default What's a callback function?

    Of course, there's many many answers online about what it is, but I just can't wrap my head around it. I was hoping someone could give me an example of one using pascal/simba, maybe then I'll be able to understand.

  2. #2
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    A callback function is usually just a method you pass to some class or structure (often a GUI form), so that it can notify you / your script if some event happens, like a key being pressed in a GUI form, so that you can do stuff in your GUI with that knowledge.

    here is a very basic example:
    Simba Code:
    procedure EventLoop(Callback: procedure); //this would normally be a form or similar
    begin
      IsMouseButtonDown(mouse_Left); //clear it (just ignore this)
      while True do
      begin
        if IsMouseButtonDown(mouse_Left) then
          Callback(); // Call the callback method to notify the scripter the mouse was pressed
        Wait(50);
      end;
    end;

    procedure MyCallbackFunc();
    begin
      WriteLn('The mouse was clicked, waiting till its released');
      while IsMouseButtonDown(mouse_Left) do
        Wait(50);
    end;

    begin
      EventLoop(@MyCallbackFunc);
    end.


    RSWalker has some callbacks, like when you are walking it can call back to a function in your script so that you can for-example stop the walking half-way, or you can search for objects while it's walking, and such. Like every click RSW does, it can notify a method in your script about that click - that's the whole point of callbacks.
    Last edited by slacky; 03-08-2018 at 07:54 AM.
    !No priv. messages please

  3. #3
    Join Date
    Dec 2006
    Location
    Program TEXAS home of AUTOERS
    Posts
    7,934
    Mentioned
    26 Post(s)
    Quoted
    237 Post(s)

    Default

    Quote Originally Posted by slacky View Post
    A callback function is usually just a method you pass to some class or structure (often a GUI form), so that it can notify you / your script if some event happens, like a key being pressed in a GUI form, so that you can do stuff in your GUI with that knowledge.

    here is a very basic example:
    Simba Code:
    procedure EventLoop(Callback: procedure); //this would normally be a form or similar
    begin
      IsMouseButtonDown(mouse_Left); //clear it (just ignore this)
      while True do
      begin
        if IsMouseButtonDown(mouse_Left) then
          Callback(); // Call the callback method to notify the scripter the mouse was pressed
        Wait(50);
      end;
    end;

    procedure MyCallbackFunc();
    begin
      WriteLn('The mouse was clicked, waiting till its released');
      while IsMouseButtonDown(mouse_Left) do
        Wait(50);
    end;

    begin
      EventLoop(@MyCallbackFunc);
    end.


    RSWalker has some callbacks, like when you are walking it can call back to a function in your script so that you can for-example stop the walking half-way, or you can search for objects while it's walking, and such. Like every click RSW does, it can notify a method in your script about that click - that's the whole point of callbacks.
    Great explanation

  4. #4
    Join Date
    Oct 2015
    Location
    Nowhere
    Posts
    134
    Mentioned
    2 Post(s)
    Quoted
    64 Post(s)

    Default

    Alright I get it, I think. I think an issue I'm having is I haven't ever encountered a situation where I would need this. I suppose it'll solidify in my mind if I ever actually need to make use of it.. Thanks slacky

    edit: missed your RSWalker example. Okay now I think I really do get it. So I assume with the RSWalker example, you can just choose to run whichever procedure inside of the RSW click. Yeah I can see why that'd be useful

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    bump having trouble I think this is my solution... but the example online don't really apply they are difficult to understand


    I have am listening to the keyboard with winapi, and when I press a certain button I need it to be unhooked, and then rehooked. can unhook fine, but the problem is rehooking.

    or maybe its this fucking loop

    [codewhile (GetMessage(&msg, NULL, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }[/code]

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
  •