Async call inside a function undifined

We’ve just implemented a neural net to hopefully create intresting maps :slight_smile:
My problem is the answers a ansyncrone and I’ve a lot of problems dealing wisth callback-functions, await and promises then :frowning:

my call always returns an undifinded…:
Perhaps someone can hint me what I’m doing wrong?

async function getAmmoPred() {
       let response = await ammoPred(LevelMap.length);
    }
    
    getAmmoPred().then(res =>
        console.log(res)
                       /*
        autoAmmoLimit = res;
        */
    ).catch(err => console.log(err));

I could solve this one… the function with includes an async callback function has to be async as well :crazy_face: So we stay with an old fashion promise … then. “Await” seams to be a bit to advanced for me :grinning:

Hi @Gurki,

Since you are calling getAmmoPred() like a promise don’t use await just return a promise and it will work (as long as ammoPred() returns a promise):

function getAmmoPred() {
   // ammoPred() needs to return a promise here
   return ammoPred(LevelMap.length);
}
    
    getAmmoPred().then(res =>
        console.log(res)
                       /*
        autoAmmoLimit = res;
        */
    ).catch(err => console.log(err));
3 Likes

cool -that works just fine :smile:

1 Like