What is a callback function?

I’ve read an article about Network Delay, though something called a callback function was mentioned. What does this mean?

1 Like

Callback function refers to a server to a client and then goes back to the server(It is basically just running the client side and once it is done,it will go back to the server and run

1 Like

I hope there is another way to get the player without touching or using game.Player.PlayerAdded

A callback is simply a function inside another function which is passed as a argument and then invoked later on the function, for example

function sum(a: number, b: number, callback): ()
    local getSum = a + b :: number
    return callback(getSum)
end

sum(5, 10, function(getsum)
    print(getsum)
end)

In this case I am using a and b as the its first two parameters as numbers then using a callback variable to define a function, with which then in the next line I will return getsum with collected arguments. In the next line I would then call sum with passing two variables and a function as its arguments to print the sum of the two numbers given by the argument given when its returned by sum.

Another example will be

function functionOne()
   print('Hi Hello!')
end

function functionTwo(callFunction1)
  callFunction1()
end

functionTwo(functionOne)

In this case I would be stating a two functions, one function will print a message for example, the other has a parameter which would be another function to be called as I’ve called it below in function two calling it back, essentially then I would call function two with its parameter which would be function 1 to execute whatever function 1 does

2 Likes