Specifiers
A function specifier is a keyword that modifies the behavior of a function.
It appears before the fn keyword in the function declaration.
Multiple functions may exist with the same name, but different specifiers.
The function specifier may change how the function must be called.
Normal functions
Most functions will be declared without a specifier.
fn MyFunction() {
// ...
}
fn Example() {
MyFunction // calls MyFunction
}
Set function
The set fn specifier is used to declare a function that performs a set,
whatever that means in the context of the function.
It is invoked by using an assignment statement.
set fn this.PowerLevel = power {
DrawPowerLevel(power)
}
fn this.Example() {
PowerLevel = 9000
}
Compound assignment set functions
It is possible to also declare specific set functions for the compound assignment operators += and -=.
This can allow your code to be more expressive:
set fn this.PowerGems += gem {
AddPowerGem(gem)
}
set fn this.PowerGems -= gem {
RemovePowerGem(gem)
}
fn this.Example() {
PowerGems += $ruby
PowerGems -= $sapphire
}
Delete function
The delete fn specifier is used to declare a function that performs a delete,
whatever that means in the context of the function.
It is invoked by using the delete keyword.
delete fn this.Healthbar {
// ...
}
fn this.Example() {
delete Healthbar
}
Await functions
The await fn specifier is used to declare what happens when the await keyword is used.
Normally, an await function is not expected to return immediately.
Instead, it may perform some processing or waiting for some number of ticks before returning.
Any functions which do not return immediately should be declared as an await fn
so callers know what to expect.
await fn WaitThenGiveMeANumber() -> value {
// wait for 10 ticks before returning
await Tick(10)
return 123
}
fn World.Example() {
let x = await WaitThenGiveMeANumber
Print { "The number is: " + x }
once WaitThenGiveMeANumber value {
Print { "Once again, the number is: " + x }
}
}
Await functions may be called directly using the await keyword,
which will block the current thread of execution until the result is ready, and then return the result.
Alternatively, a with, on or once block can be used to wait for the result in a concurrent thread.
See behaviors for more details.
Unlike other programming languages, in Easel any function can perform an await,
even if it is not inside a function declared as an await fn.
But it is good practice to declare a function as an await fn if it performs an await
so callers know what to expect.
Entrypoint functions
The page fn specifier is used to declare a function that is the entrypoint
when a user navigates to a particular page in the game.
The game fn specifier is used to declare a function that is the entrypoint
when a user navigates to play the game.
See the entrypoints page for more information.