# Error comparing variables

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?

Here is the Script:

Var

``````P1 : Parameter := 1.0000000
P2 : Parameter := 0.0000000
``````

initialization

``````select

P1 == 0.0000000 do

Print("P1 == 0.0000000")

P1 == P2 do

Print("Same")
end
``````

end

I can reproduce

Here is a workaround

``````var
P1 : Parameter := 1.0000000
P2 : Parameter := 1.0000000

initialization

select

P1 == 0.0000000 do

Print("P1 == 0.0000000")

P2 == (P1+0.0) do

Print("Same")
end
end
``````

Thanks for the workaround … but why the syntax error? You would think GP Script would know the variables are floats at this point?

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.

Yes, thanks. After playing around with this comparison code, I later found that I had to do this with both integer variables as well EG:

var
P1Pos : parameter 1…5 = 4;
P2Pos : parameter 1…5 = 1;

``````select
(P1Pos+0) == (P2Pos+0) do
Print ("same")
end
``````

I think in internal structures the parameters are strings.

Is this a derivative of the same problem?

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

I think a static array must have a fixed length at compile time.
So the compiler does not now the actual value of variables.

Or you use a dynamic array
DArray : Integer array

No - the array size must be an constant, not an expression.

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

1 Like

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

Thanks Paul. I never considered arrays to be static. I will use “Darray” from now on for obvious reasons. 