I have a library that I call from my main project module.
In this library, I set up some global constants.
Then, I tried to make another constant for a default value that assigns the value of one of the above constants, like this: (In Tween.gbas)
CONSTANT kTweenTransition_Linear = 1
CONSTANT kTweenTransition_Spring = 2
CONSTANT kTweenTransition_Bounce = 3
CONSTANT kTweenTransition_Default = kTweenTransition_Spring
But, in my main module, when I refer to the constant that was assigned as default (kTweenTransition_Spring in this case), I get this C++ error:
error: `kTweenTransition_Spring' was not declared in this scope.
But when I assign a hard coded value like:
CONSTANT kTweenTransition_Default = 2
everything works fine.
It seems assigning a constant to a constant causes the original constant to be declared earlier in the compiling cycle?
[edit]
Or never gets created in the first place?
Or because it would have been created as a standard float in the first pass?
I don't know if it is related but this sounds just like the declacaration of a variable and initializing it with another variable. A clear no-no :-)
GLOBAL a = 5
GLOBAL b = a // might not work
GLOBAL b
b = a // will always work
hmmm for me it works without any error.
CONSTANT kTweenTransition_Linear = 1
CONSTANT kTweenTransition_Spring = 2
CONSTANT kTweenTransition_Bounce = 3
CONSTANT kTweenTransition_Default = kTweenTransition_Spring
which version of GLBasic you're using?
I had a similar error but only when a constant was used in an external program, that is, not declared in the main program of a project.
Substituting GLOBALS works fine for now.
Cheers,
Ian
I'm using GLBasic 7.341, demo.
I can recreate this using these 4 lines:
In main.gbas:
LOCAL speed = kFast
And in library.gbas:
CONSTANT kSlow = 1
CONSTANT kFast = 2
CONSTANT kSpeedDefault = kFast
This will trigger the compile error.
But if I simply change the main.gbas to:
LOCAL speed = kSlow
everything compiles fine, because I'm not referring to the value assigned to kSpeedDefault.
If all of the above code is in the same module, I don't get any compile errors.
The work-around in this case is just to never use other constants as a default value for constants, but hard code them, as in:
CONSTANT kSpeedDefault = 2
Thanks for your comments and suggestions.
Its mainly due to variable definition rules - the secondary file isn't compiled before the main file...