Repository navigation
Tutorials: Methods & Access Modifiers
A method is a function that is class-specific, the signature is pretty much identical to skript functions.
class Example:
public helloWorld():
broadcast "hello world"
public 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)Public means something can be accessed from anywhere as long as there is an instance available. You can also prefix methods and fields with the private modifier to restrict their access to only within the same class.
class Example:
private exampleField: boolean = false
private exampleMethod():
broadcast "i can only be accessed internally!"This brings us onto the self 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 dateIssued: date
private duration: timespan
public isActive() :: boolean:
if time since self::dateIssued < self::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.