0

I am trying to write a method that uses the scryfall sdk to get a card by name. However the problem is, that the method does not return any value. The console.log is working, but the tempResult variable never gets a value and always returns an empty string. I guess I am doing something wrong with the lambda function but I dont know what.

public getCardsByCardNameFromScryfall(cardName) : any{
    var tempResult; 
    Scry.Cards.byName(cardName, true).then(result => {
      console.log(result.name);
      tempResult = result.name;
    });
    return tempResult;
  }

Does anybody have an idea? Thank you :)

Rachid O
  • 13,013
  • 15
  • 66
  • 92
  • 1
    your method is returning value before `then` clause set the value to `tempResult`. So, you are not getting value in response. – Nayan Jan 31 '21 at 09:18

1 Answers1

0

if Scry.Cards.byName(cardName, true) returns a promise you could simply await it

async function getCardsByCardNameFromScryfall(cardName) {
    var tempResult = await Scry.Cards.byName(cardName, true);
    return tempResult.name;
}
Rachid O
  • 13,013
  • 15
  • 66
  • 92