What about async functions?

I use game lab. I have been using it for almost 2 years and I recently realized that there is a javascript feature that isnt in game lab (if that makes sense). Its async functions. Like, am I doing something wrong? Because when I type:
async function helloworld() {
console.log(“Hello World!”)
}
it says “‘async’ hasn’t been declared yet.” Game lab’s coding language is javascript so I wouldn’t see why async functions wont work. When i try to use async functions on Visual Studio Code, it works.
If anyone knows how to use async functions in game lab, please help lol

@MonsterYT_ALT,

Game Lab was built on the ES5 version of Javascript. Async functions weren’t a part of Javascript until ES8, so that’s why they don’t work.

Good luck!

Mike

1 Like

Greetings @MonsterYT_ALT,

In regards to your question it’s the way @mwood described, However there is such a way to mimic some form of that functionality so long as you don’t mind callbacks which is what most of ES5 relies on for asynchronous execution,

let me give you a basic rundown on how it operates

function asyncEcho(txt, callback) {
setTimeout(function() {
console.log(txt); // executes back what you said a second ago
if(typeof callback === 'function') {
callback();
} // sanitizes the callback if nothing is used
}, 1e3) // 1e3, scientific notation for 1,000 ms or 1 second 
}
// Let's put this function to actual use
asyncEcho("Hello", function() {
console.log("World");
});

Do keep in mind that anything you want executed after the callback needs to exist within it as I have stated (this is not a replacement for the keyword async nor does it mimic exact behavior befitting of ES6) but this should in theory be close enough if you are looking for something that can fill in what asnyc does