Using own functions in rules file

This, by definition, means you are using DSL as the rules language. DSL has limited capability for reusable code snippets. Declarations of function will not work as they are not part of the language.

You have a couple of choices:

  1. Stick with DSL and read up on lambdas. You probably want to start here:
  1. Move your rules to any of the other language options which have much better systems for functions.

I highly recommend option #2. The limitations of of DSL are many and if you’re trying for more advanced code like this you will likely run into many more such issues. Even if you are not highly experienced with coding, you have options. The UI Blockly implementation gives you the chance to define your own functions.