Understanding Arrays

I recently used some variable Arrays in a script when i noticed the following behaviour:

having defined some variables

VarM1, VarM2 : double

then i put them into an Array

VarAr : double Array = [VarM1, VarM2]

i expected that when i wrote

VarM1 = 0.5

then the according array index VarAr[0] would contain the same value, because in my variables definition i used this variable VarM1 as the item [0] of the Array.
I thought that VarAr[0] and VarM1 would always have the same content and only the “addressing” would be a diffrent one… but as it turned out, the variable VarM1 and the content of the Array VarAr[0] are two completely diffrent things which, during run time, don’t have any relationship anymore.

On my search for an answer i found this statement from @dhj

Which would perfectly explain the described behaviour…
(But this still is some kind of confusing for me)

That statement assigns the value of ‘VarM1’ to VarAr[0] and the value of VarM2 to VarAr[1]. It is not assigning the addresses of those variables – remember that the type of that array is double so the array expects double values at every index.

Consider the following as an analogy

VarAr : double Array = [42, 65]

You could not then write

42 = 0.5

Incidentally, since you didn’t initialize those variable, the actual values in the first two entries of VarAr will be random


Makes perfect sense… thanks for the clarification. :+1: