Object Parameters
Functions can take an object parameter, which is a special kind of parameter
that comes before the .
in a function call.
fn vegetable.FunctionThatTakesAnObject() { }
fn Example(carrot) {
carrot.FunctionThatTakesAnObject
}
If the object parameter is not passed in explicitly, it will be found from context. It is conventional to not specify the object parameter directly and instead let it be found from context.
fn vegetable.FunctionThatTakesAnObject() { }
fn Example(carrot) {
Spawn vegetable {
FunctionThatTakesAnObject // the object parameter `vegetable` is found from context
}
}
Automatic 'this' declaration
The object of a function automatically gets bounded to the special this
variable.
The this
variable is a special variable that denotes the current entity that is being operated on.
Learn more about this
here.
fn projectile.Fireball() {
this.DoSomethingCool // `this` refers to the `projectile`
}