Hi,
Fell foul of this once, even knowing, by accident used twice but drew a line via RETURN line with the first one of them. The line was not correct, but when I checked the code it should have been right.
My checking stopped once I checked the first iteration of the name, didn’t fined it till a re-wrote the program bit by bit and then later came across the same name used for a similar but different value.
Generally, when a value is assigned to a variable, the variable name is a reference to the location where the value is stored.
When assigning a new value to the variable, later in program, the new value is stored at the same location.
Since a location can only hold one value, the first value is overwritten with the second.
As you point out, other languages have some sort of ‘variable scope’ which allows using the same variable name which gets a different storage location depending on where/how the variable is defined.
This usually happens if variable names are case sensitive or defined variables inside certain code blocks are treated differently.
With the ProBuilder language, variable name are not case sensitive and variable names need to be unique generally, usually all have a global scope.
I think the only time I have seen the variable name being used more than once is with an array name, since the element index differentiates between the value locations.
This can come in handy in grabbing the same constant values from different timeframes in which you want to access with the same name and select the different values with an index value.
This avoid error message for defining same name in different timeframes.
When call’ing another indicator file into your program, a clash in names is avoided since the returned variable values are assigned to new variables, which must be unique to the main program.
regards
1 user thanked author for this post.