setFunction

open fun setFunction(@NotNull key: @NotNull String, @NotNull function: @NotNull KeyframeRuntimeContext.FloatFunction0)

Binds a Molang query that accepts no arguments. The function runs when Molang evaluates the query. The default implementation ignores the binding.


context.setFunction("health", () -> 20F);
float value = evaluator.compile("q.health()").eval(context);

Since

3.7.0

Parameters

key

the query name without the query. or q. prefix

function

the function that computes the query value


open fun setFunction(@NotNull key: @NotNull String, @NotNull function: @NotNull KeyframeRuntimeContext.FloatFunction1)

Binds a Molang query that accepts one numeric argument. The function runs when Molang evaluates the query. The default implementation ignores the binding.


context.setFunction("echo", x -> x);
float value = evaluator.compile("q.echo(1)").eval(context);

Since

3.7.0

Parameters

key

the query name without the query. or q. prefix

function

the function that computes the query value


open fun setFunction(@NotNull key: @NotNull String, @NotNull function: @NotNull KeyframeRuntimeContext.FloatFunction2)

Binds a Molang query that accepts two numeric arguments. The function runs when Molang evaluates the query. The default implementation ignores the binding.


context.setFunction("sum_two", (x, y) -> x + y);
float value = evaluator.compile("q.sum_two(1, 2)").eval(context);

Since

3.7.0

Parameters

key

the query name without the query. or q. prefix

function

the function that computes the query value


open fun setFunction(@NotNull key: @NotNull String, @NotNull function: @NotNull KeyframeRuntimeContext.FloatFunction3)

Binds a Molang query that accepts three numeric arguments. The function runs when Molang evaluates the query. The default implementation ignores the binding.


context.setFunction("sum_three", (x, y, z) -> x + y + z);
float value = evaluator.compile("q.sum_three(1, 2, 3)").eval(context);

Since

3.7.0

Parameters

key

the query name without the query. or q. prefix

function

the function that computes the query value