function
function <name>(<locals>):since 1.5.6Any script
function reward({_who}, {_amount}):
add {_amount} to {%{_who}%.coins}
return {%{_who}%.coins}Try it← All of the Docs The basics
function <name>(<locals>):since 1.5.6Any script
function reward({_who}, {_amount}):
add {_amount} to {%{_who}%.coins}
return {%{_who}%.coins}Try itlocal function <name>(<locals>):since 1.5.6Only the file it is written in
local function prefix():
return "&7[&bShop&7] "Try itA function is a block with a name. Write it once, at the left margin like a command, and call it from anywhere:
function reward({_who}, {_amount}):
add {_amount} to {%{_who}%.coins}
send "&a+%{_amount}% coins" to {_who}
return {%{_who}%.coins}
command /daily:
cooldown: 1 day
trigger:
set {_total} to reward(player.name, 50)
send "&7You now have %{_total}% coins."
| Form | Can be called from |
|---|---|
function <name>(<locals>): | Any script |
local function <name>(<locals>): | Only the file it is written in |
function refresh(): and called refresh().function reward({_who}, {_amount} = 10): can be called as reward(player.name) or reward(player.name, 50). Parameters with a default come last.reward(player.name, 50)) or anywhere a value is expected (set {_total} to reward(player.name, 50), if is_rich(player.name):).return <value> leaves the function and hands the value back; return on its own just leaves. A function that never returns a value gives unset.player and the event values are those of whoever called it. Its locals are its own: it cannot see the caller's locals, and the caller cannot see its.function is shared by every script, in whatever order the files load, so two scripts may not both define a shared function of the same name; the second one is refused with a message naming the first. Use local function for helpers that only one file needs. When both exist, a file's own local function is the one it gets._, and may not be a word that starts a statement, such as send or give.wait inside a function pauses the function only: the caller carries on at once, and gets whatever had been returned by then (normally nothing).