Rule Machine Global Variables Should allow initialize

I have a global variable stuck at null. I want to use it as a counter, but I can't add anything to it (can't add to null). When I created it, I wanted to initialize to 0, but there was no way to do that. So I was getting this:
java.lang.NullPointerException: Cannot execute null+1 (addVar)
Until I wrote a trigger to initialize it. A lot of work for what amounts to:
int intCounter = 0;

Also, something happened last night, and the variable was back to null, and everything was broken.
Is there an easier way?

Can you share the code?

In the meantime I'd suggest using something like

intCounter = (intCounter ?: 0) + 1

I suspect the problem is that global variables aren't actually global, better to use a state variable, although that will only persist at the end of execution.

Hi, I am talking about the Global Variables in Rule Machine. I should have made that clear. I will update the title. Thanks.

Ah, fair enough.

I've not had to use them yet, all my rules are pretty simple.

This feature is in the upcoming release of Rule 3.0. In fact, you have to initialize them.

1 Like

Thank you Bruce, looking forward to that.