I am trying to compare variables using the expression “P1 == P2” but GP Script is yielding an error and is telling me it is expecting a “double expression”. I am confused because both P1 and P2 are doubles?
Errors can happen and the explaination behind this particular one is very very complicated
By the way, take care that in you example, if P1 and P2 are both initialized to 0.0, both of your select conditions are “true”, but only the first one will be taken into consideration.
Var
NumberOfChannels : Integer = 5
PositionsArray : Integer[NumberOfChannels+0]
error msg: Syntax Error in “Main”: Line 6, Col 30: Unexpected or unrecognized token: ‘NumberOfChannels’
Mismatched input ‘NumberOfChannels’ expecting Integer
The variables are not floats. They are parameters that represent (in this case) doubles, per your declaration.
P1 : Parameter = ....
I did some (perhaps too) cute automatic reinterpretation when parameters are used in conjunction with doubles (or integers or strings in the case of parameters that represent integers or strings respectively) to avoid the need to use functions to get and set their values.
That said, the issue you found is interesting but requires some thinking
In particular, when you write something like
if P1 == P2 ...
the question is whether that should be testing to see if P1 and P2 are the same parameter (which obviously they’re not in this case) but consider what should happen if you pass a parameter to a function and you want to know what parameter you’ve got.
I will put this in our tracking system for further investigation
Interesting thought My thoughts: P1 and P2 are objects and therefore you should be testing their property values in some respect. Considering my line of thinking for a moment: Couldn’t P1/P2 have properties? … for example - a name, a value, etc.? EG: P1.Value