Would it be possible to allow INLINE code to declare global variables? It would be good if having "GLOBAL int myvar;" would cause GLB to move the declaration outside of any functions, allowing us to declare global variables of any type in inline code. Is this okay to implement?
No. If you want an inline global, define it outside a function, or use GLOBAL for float/int.
Defining vars in inline outside functions and subs doesn't seem to make it global... Isn't the main GLB program inside a C++ func.? If so it's physically impossible to define vars outside of any function...
Anyway this should compile if INLINE vars outside of functions in GLB are global:
INLINE
DGInt MyVar = 5;
ENDINLINE
GOSUB MySub
SUB MySub:
LOCAL GLVar#
INLINE
GLVar = MyVar; //error - MyVar not declared in this scope...
ENDINLINE
PRINT GLVar, 10, 10;
SHOWSCREEN
KEYWAIT
END
ENDSUB
The compiler reports that 'MyVar' was not declared in the scope of the sub. If it was globalled this shouldn't happen...
It's not a big deal but it would be nice to have this extra functionality if it isn't too hard to implement, and won't allow us to mess up GLBasic's internal workings...
it's in "main()" now - you must end main with a dummy function, or a new gbas file.
Oh I get it now! Thanks!
This works:
foo()
foo2()
FUNCTION dummy:
ENDFUNCTION
INLINE
DGInt myvar;
ENDINLINE
FUNCTION foo:
INLINE
myvar = 0.5;
ENDINLINE
ENDFUNCTION
FUNCTION foo2:
LOCAL GLVar
INLINE
GLVar = myvar;
ENDINLINE
PRINT GLVar, 10, 10
SHOWSCREEN
KEYWAIT
END
ENDFUNCTION