How does Sugarcube 2 handle async functions?

I want to create a relatively complex game in Sugarcube, but I’m confused as to how async functions would work.

If I start an async function during a passage, will that function continue to run after the player navigates away from that passage? Is an async function able to alter variables and the story state as the player navigates?

Twine/SugarCube won’t do anything to affect how asynchronous functions work.

If you call an async function, and then some of your code in the the passage tries to access data from that function before it has finished, then that data simply won’t be there. Changing passages won’t cancel async functions either.

Yes, async functions can alter values and the story state as soon as they complete. Exactly what they do and how they do it at that point is entirely up to you and your code.

If you take a look at the “Geolocation Access” section of my Twine/SugarCube sample code collection , it shows an example of an asynchronous call to the Geolocation API to find the latitude and longitude of your location.

Hope that helps! :slight_smile:

I tested things out and okay, I see how it works now.