1

I want to use method getPlayers(callback) which is defined as:
getPlayers(callback)
callback - Required. Called with an object of players players - An object containing all the players connected to the server, with their name as the key
Retrieve all players connected to the server.
Here is the link to complete module for further details :
https://www.npmjs.com/package/hltv-livescore#getplayerscallback

2 Answers 2

2

If you want to use it and access the data, you'll need to do something like this:

getPlayers(function(players) {
    // Here your players will be available
    console.log(players)
})

Bonus: If you're using ES6, you can use Arrow functions, that are more elegant, like this (single line):

getPlayers(players => console.log(players))

or (multi line):

getPlayers(players => {
    console.log(players)
})

You can read more about the async nature of Javascript here

Sign up to request clarification or add additional context in comments.

Comments

1

If you refer source code of npm package you can see this code https://github.com/andrewda/hltv-livescore/blob/master/lib/index.js#L78

Livescore.prototype.getPlayers = function(callback) {
callback(self.players);
};

You can use getPlayers like this :

Livescore.getPlayers(function(players){
 // you will get players here 
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.