Previousvalue and CurrentValue facing issue

Hi,
I am trying to implement a logic when current alarm count is greater than previous alarm count audio should play.

I have written change script on a numeric input field value for testing purpose and manually updating the numeric field and in both condition either the alarm count is greater or lesser than previous count audio is playing.

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	system.perspective.print(("Previous Value :", previousValue))
	system.perspective.print(("current Value :", currentValue))
	
	if currentValue > previousValue :
		self.getSibling("Audio").props.play = True
	else:
		self.getSibling("Audio").props.play = False
		
	system.perspective.print("--------------------------------------------------------")

and in console I am getting below output. (change the value from 7 to 10 in numeric field)

('Previous Value :', [7, Good, Wed Oct 11 15:46:01 IST 2023 (1697019361552)])
('current Value :', [10, Good_Unspecified, Wed Oct 11 15:46:06 IST 2023 (1697019366321)])

('Previous Value :', [10, Good_Unspecified, Wed Oct 11 15:46:06 IST 2023 (1697019366321)])
('current Value :', [10, Good, Wed Oct 11 15:46:06 IST 2023 (1697019366328)])

I don't understand why 2 times print statement executing and why audio is playing in both condition.

Any suggestions, thanks

It's printing twice because the tag quality changes and triggers the valueChanged script again. Also, I normally see a .value on the end of these comparison variables, so the entire list is not being compared.

2 Likes

Its working only when count is greater than previousvalue.

After putting .value in print statement I am getting below output.

Do you have any idea what L means?


--------------------------------------------------------
PerspectiveClient.3a86a04588cd08dbba6d.js:2 ('Previous Value :', 15)
PerspectiveClient.3a86a04588cd08dbba6d.js:2 ('current Value :', 21L)
PerspectiveClient.3a86a04588cd08dbba6d.js:2 --------------------------------------------------------
PerspectiveClient.3a86a04588cd08dbba6d.js:2 ('Previous Value :', 21L)
PerspectiveClient.3a86a04588cd08dbba6d.js:2 ('current Value :', 21)
PerspectiveClient.3a86a04588cd08dbba6d.js:2 --------------------------------------------------------

thanks for guidance.

It's just an indicator for the print console that the value is seen as a long integer.

1 Like

There are some considerations to be made as to what should happen if previousValue doesn't have a value, but you can simplify your script a bit with something like this:

if currentValue and previousValue:
    self.getSibling("Audio").props.play = currentValue.value > previousValue.value
3 Likes

Noted, Thanks