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

Where can information be found about: parameter ?

What information are you looking for?

what does 'Aantal-1': number positive 'willekeurig' = parameter @hidden parameter refer to,
a collection, a node, an expression or something else?
since parameter is positioned after the = sign it has to refer to something.
in tutorial part 2 there it is also mentioned in an example without an explanation.

= parameter means that the value is a parameter, provided by a node initializer, as shown on line 4 of my code sample:

( 'Aantal-1' = $ )

thanks for the explanation, this makes it very clear.