Repository navigation
Tutorials: Methods & Access Modifiers
A method is a function that is class-specific, the signature is identical to skript functions.
class example:
method helloWorld():
broadcast "hello world"
method getBalance(p: player) :: number:
return balance of {_p}Calling methods:
set {_example} to new instance of example
{_example}::helloWorld()
set {_balance} to {_example}::getBalance(player)By default methods and fields are public, meaning they can be accessed from anywhere as long as there is an instance available. You can prefix methods and fields with the private modifier to restrict their access to only within the same class.
class Example:
private field exampleField: boolean = false
private method exampleMethod():
broadcast "i can only be accessed internally!"This brings us onto the instance expression; it's only available in methods and refers to the current class instance from whatever method is running it. This means your code may behave differently depending on what instance is running it.
class banEntry:
private field dateIssued: date
private field duration: timespan
method isActive() :: boolean:
if time since instance::dateIssued < instance::duration:
return true
return false
Think of private fields as a nice middle ground between {_local} and {-memory} variables, where you can be sure that other code won't interfere with yours but you're still able to store things persistently.