setFunction
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
the query name without the query. or q. prefix
the function that computes the query value
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
the query name without the query. or q. prefix
the function that computes the query value
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
the query name without the query. or q. prefix
the function that computes the query value
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
the query name without the query. or q. prefix
the function that computes the query value