Any script can be imported by another script by its file name. This is how you share code between scripts without copying it.
plugins/Flint/scripts/coins.fl:
persist balances = {}
fn get(p):
return balances[p.uuid] or 0
fn add(p, amount = 1):
balances[p.uuid] = get(p) + amount
_announce(p, amount)
fn _announce(p, amount): # names starting with _ are private to this file
p.action_bar("<gold>+{amount} coins")
plugins/Flint/scripts/rewards.fl:
import coins
from coins import get
on block.break:
if block.type == "diamond_ore":
coins.add(player, 25)
command coins:
send "You have {get(sender)} coins" to sender
Rules
- The module name is the file name without
.fl. The file can be in a sub-folder. A built-in or addon module with the same name wins. - Every top-level
fnis a member of the module. Functions starting with_are private. - Variables (including
persist) stay inside the module’s file, so every script that imports it shares the same data. - A module is a normal script: it can have its own events, commands and timers.
- Module functions may
waitand use databases; the calling script pauses until they return. Errors can be caught withtry/catchin the calling script. - Scripts cannot import each other in a circle; you get a clear load error.
The VS Code extension knows about the other scripts in your workspace, so coins. completes get and add with their parameters.