How to add a negative number to a positive number?

There is a very simple command that should decrement a value. It is used in a custom client which has buttons to increment or decrement an amount.

I would think the sum operation does the trick, but that results in an error message:

no valid 'integer target' found for 'type' option 'sign inversion'. Unexpected 'number set type'

Also wrapping it in a a min operation does not solve the problem. Maybe a bit naive on my part :slight_smile: .

'Aantal': number positive 'willekeurig'
'-': command { } => update (
	'Aantal' = sum (
		.'Aantal' ,
		- 1
	)
)

The error is because the sum can be 0, while Aantal has to be a positive number according to your model. You can solve it by removing the positive keyword.

If you need Aantal to be positive number, you can do this to ensure it:

'Aantal': number positive 'willekeurig'
'Aantal-1': number 'willekeurig' = sum ( .'Aantal', -1 ) @hidden
'Can be decremented': stategroup = switch .'Aantal-1' compare ( 0 ) (
	| >  as $ => 'Yes' ( 'Aantal-1' = $ )
	| <= => 'No' ( )
) (
	'No' { }
	'Yes' {
		'Aantal-1': number positive 'willekeurig' = parameter @hidden
		'-': command { } => update ^ .'Aantal' = .'Aantal-1'
	}
)

We plan to support the switch statement in command implementations such that you can write it in a more concise manner.

1 Like