[SOLVED] Math error in rules

Hi. I’m trying to do some small math in my rule.
I get the following error:

2019-05-04 14:09:46.825 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'elektriHind': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null

rule:

		val Number marginaal = 0.001
		val Number elektriaktsiis = 0.00447
		val Number taastuvenergia_tasu = 0.0104
		val Number elektri_edastamine_paev = 0.0423 //kell x-y
		val Number elektri_edastamine_oo = 0.0246 //kell y-x
		val Number VAT = 1.2

rule "elektriHind"
	when 
		Item RunRule changed or
		Time cron "0 0/1 * 1/1 * ? *"

	then
		var Number x = (NP_Electricity_price_current.state + marginaal + elektriaktsiis + taastuvenergia_tasu + elektri_edastamine_paev)*VAT
		//ElektriHind.postUpdate(x)
		Dummy1.postUpdate(x)
end

when I crop the code like this then it works:

var Number x = NP_Electricity_price_current.state

or

var Number x = (marginaal + elektriaktsiis + taastuvenergia_tasu + elektri_edastamine_paev)*VAT

but when I combine them then I get the error.
Everything is defined as Number.
Whats the trick?

Does converting the item state to number work, like this:

var Number x = (NP_Electricity_price_current.state as Number + marginaal + elektriaktsiis + taastuvenergia_tasu + elektri_edastamine_paev) * VAT

It worked- thanks !
But I don’t understand why it was needed as it was already a Number:

someItem.state gives a state object, not a Number object. That can have the values NULL or UNDEF for example, which a Number variable cannot.

It is subtle but thay are different.

1 Like