The define statement will only set the value if it is not defined in any scope. In your case you have duplicate variables with the same name in different scopes, so define is not and cannot work as you intended.
You wound up with this code:
GTest = GTest
If Error GTest = "" EndIf
You say this works, but if there is a fileglobal variable named GTest, that is the variable being referenced in the second and third lines. You did create a global variable, but it still has no defined value. So I think this code actually isn’t working the way you intended.
Panorama X does allow you to create code that will assign a value to this global variable. In fact it can be done in a single line.
letglobal GTest = catcherror("",globalvalue("GTest"))
If there is a concern that there might be a fileglobal variable named GTest, as apparently there is in this case, you should only ever reference this global value with the globalvalue( function, never by just using the variable name. That way there is no possible ambiguity about what variable is being referenced. Any other variable (or field) with the same name will be ignored.
Here is a code example I created to show how two variables with the same name in different scopes can be used:
Here is the instrumentation output from running this code:
[Untitled/Procedure_F] testVariable: local
[Untitled/Procedure_F] fileglobalvalue("testVariable") --> fileglobal
If you have access to the Fields & Variables video course from 2015, I spent the better part of an hour discussing how different variable scopes interact.
The simplest way to deal with this is to avoid using global variables if at all possible, and if you do use them, give them really long descriptive names. If you are using global variables to hold preference values, consider using getpreferencevalue( and setpreferencevalues instead.