Configuring and using scripting
Another use for Zircon is the ability to programmatically manipulate your game during runtime.
By default, script execution is limited to only the creator of the game or group owner.
#
Adding FunctionsFunctions in Zircon use the Zirconium language and thus are sandboxed + use the syntax of that language
import { ZirconServer, ZirconFunctionBuilder } from "@rbxts/zircon";import Log from "@rbxts/log";
const MyFunction = new ZirconFunctionBuilder("print_message") .AddArgument("string") .Bind((context, message) => Log.Info( "Zircon says {Message} from {Player}", message, context.GetExecutor() ));
// Zircon server is initialized via the init callZirconServer.Registry.Init( ZirconConfigurationBuilder.default() .AddFunction(MyFunction, [ZirconDefaultGroup.User]) .Build());
This will create a global print_message
that all players can run.
Then if run in Zircon:
ZirconServer.Registry
is the server registryZirconConfigurationBuilder
is the builder class for zircon's own configuration.- Depending on your goal with Zircon, this configuration may look different. If you're only using it for logging purposes, you can use
ZirconConfigurationBuilder.logging()
for the configuration. - If you want a quick setup, you can use
ZirconConfiguration.default()
- which includes thecreator
,admin
anduser
groups.
- Depending on your goal with Zircon, this configuration may look different. If you're only using it for logging purposes, you can use
ZirconFunctionBuilder
here is a builder class, in which allows you to configure the executable function.AddArgument
adds an argument type, internal types you can use a string id, such asstring
,number
,boolean
,player
andunknown
. This will infer the zircon function types for theBind
function + enforce type checking when this function is called.Bind
binds the arguments to the function you provide, the first argument of the function is alwayscontext
; which is the zircon runtime's context (useful for getting things like the executing player)
ZirconConfigurationBuilder.AddFunction
takes aZirconFunction
, whichZiroconFunctionBuilder.Build(...)
returns. The second argument toAddFunction
is the groups that can execute this function. By default you should limit it toZirconDefaultGroup.Creator
(which can be added viaZirconConfigurationBuilder.CreateDefaultCreatorGroup
).
The default groups available to Zircon are Creator
, Administrator
and User
. Creator
is the place or group owner, Administrator
is a group that requires explicit users and User
is any user. It is recommended that you use Creator
or Administrator
for functions.