createTime - Void functions cannot return a value

Using OH3.4 to create a timer

var Timer  signalizing_timer
if (signalizing_timer!==null) return
signalizing_timer=createTimer(now.plusMinutes(1), [ |  ...])

When loading the line “signalizing_timer!==null” marks following error “Void functions cannot return a value.”
There are a lot of examples using this syntax.
What’s wrong here?

Missing semicolon…

var Timer  signalizing_timer
if (signalizing_timer!==null) return; // < there
signalizing_timer=createTimer(now.plusMinutes(1), [ |  ...])

Udo - thanks
DSL has somehow strange syntax. rules

Well, no.

The openHAB Rules DSL does not need any semicolon, BUT.

return; is the great exception :slight_smile: but it’s reasonable, return will send an exit code to the code which called the rule.
The exit code is set after the command, so return myValue will give the value of myValue as exit code. If omitting the exit code, DSL will take the next string as return value → error.
But there is another problem. The rule is not expected to return any value, so even if setting a value, there will be an error.
The semicolon is to set the option “don’t return any exit code”.

@Udo_Hartmann explains it perfectly. But I want to add that if you are struggling with Rules DSL, OH supports many other options for rules. If you are less technical, Blockly is an excellent choice. If you prefer text based you have two flavors of JavaScript, two flavors of Python (including HABApp), Ruby, Groovy, and Java as options.

I used to be a great champion of Rules DSL because it’s relatively simple and easy to lear compared to other languages which made it a good fit for less experienced users. However, now Blockly fills that niche better.

1 Like