0

I have just returned data from my function and have confirmed using console.log that the object actually has data so i must be missing something obvious here but i just dont know.

// Variables that do not recive values
var reqSummoner = req.body.summonerName.toLowerCase();
var summonerId;
var summonerLevel;
var profileIcon;
var summonerName;
var games;
lolapi.Summoner.getByName(reqSummoner, function (err, summoner) {
    if(!err) {
        // attempting to save variables to be accessible outside function
        summonerId = summoner[reqSummoner].id;
        summonerLevel = summoner[reqSummoner].summonerLevel;
        profileIcon = summoner[reqSummoner].profileIconId;
        summonerName = summoner[reqSummoner].name;
    }
});
Steve T
  • 7,729
  • 6
  • 45
  • 65
  • `getByName()` must be asynchronous call – Satpal Dec 28 '16 at 07:10
  • You mean to say that variables set inside callback function of getByName are not visible outside? May be add few more comments on where it is going wrong. – Anurag Sinha Dec 28 '16 at 07:11
  • Try making a fiddle of it – Flying Gambit Dec 28 '16 at 07:12
  • I actually thought the code makes sense, lets see, i have declared the variables i want to access right and inside the getByName function i attempt to save data to the predefined variables however when using console.log its clear the variables are not being recieved. This is a node app so i wasnt site how to properly display a fiddle –  Dec 28 '16 at 07:18

0 Answers0