Async
In a world of schedulers, state machines, and loads of nested functions, MCCompiled's async implementation is built to remove ALL boilerplate and focus entirely on logic and structure.
Async functions generate state machines automatically, set up to either run locally on an entity or globally without any executing context (directly from tick.json
).
Defining
To define an async function, the attribute async
can be used. The attribute accepts one parameter, being the word global
or local
, which defines if the async state machine should be run globally or on the executing entity only.
Awaiting
The await
command is only usable inside async functions. It allows you to wait for a specific amount of time, wait for a condition to be met, or wait for another async function to finish executing.
Awaiting an amount of time
This is the most common use of async code. To await a certain amount of time, use the syntax await <time>
, with time
being the number of ticks to wait. You can use time suffixes to make this number more concisely defined.
Awaiting a condition
To await a condition, use either syntax depending on what makes the most sense:
await until <condition>
await while <condition>
These will wait until the given condition is true/false respectively to continue execution. You can wait until a condition is met or wait while a condition is met.
The conditions that can be used are the same as what's available with if
statements, while
loops, etc.
Awaiting another function
To wait for another async function to complete its execution, call it and pass the result as a parameter to await
. Async functions return an awaitable
, and as such are not able to return any other type of value.