Visibility
Easel has a simple visibility system where declarations can either be public or private, and can also be local to a function.
Public vs Private
In Easel, declarations can either be public or private.
Use the pub keyword to make a declaration public. If the pub keyword is not used, the declaration is private.
- Private (the default) means that the declaration can only be accessed from within the same file.
- Public (the
pubkeyword) means that the declaration can be accessed from any file in the project.
// file1.easel
fn PrivateFunction() { }
pub fn PublicFunction() { }
// file2.easel
fn Example() {
PrivateFunction() // Compilation error: unknown identifier 'PrivateFunction'
PublicFunction() // This is fine
}
Unlike other programming languages, you do not have to importing declarations from other files. If something is public, it is accessible everywhere.
Local declarations
Props, fields, and signals can also be declared local to a function. This means that the declaration will only be accessible from within that function:
pub fn unit.RejoiceSystem() {
prop unit.Happiness // local to this function
on ButtonDown(KeyR) {
Happiness = Happiness + 1
}
with Happiness {
Print { "Happiness: " + Happiness }
}
}
pub fn unit.AnotherSystem() {
// Compilation error: unknown identifier 'Happiness'
// because it is not defined in this function
Print { "Happiness: " + Happiness }
}
When inside a function, the order of statements inside a function matters - you cannot use a local declaration before it is declared. Also, if a new property, field or signal is declared with the same name as an existing one, it will shadow the existing one for the rest of the function.