Reply To: How to initialize global variable?

Product Compare Forums Multi-Edit Support How to initialize global variable? Reply To: How to initialize global variable?


Globals are a bit diffferent than you’re expecting. They aren’t global in the sense that anyone can just use them – they’ve got to be declared and aliased in any source file that will make use of them.

Global also doesn’t mean they can be used outside of a macro context – I can’t find any example of a global being initialized on declaration.

Here’s an example from one of my files:

[code:j4do3h5w]global {
int g_DebugTab "~DebugTab";

What this does is create an alias, g_DebugTab, for the global variable named ~DebugTab. (The prefix characters have a specific meaning as well, which you’ll find in the help file; some are restored on startup, some are tied to sessions, some aren’t saved at all between executions.)

You don’t actually have to use global aliases like this; Global_Str/Global_Int will work just fine, but they’re a lot less convenient. The alias can be treated as a local variable and assigned, checked, etc, just like anything else. The aliasing just saves you a lot of

[code:j4do3h5w]value = Global_Int("~DebugTab");
value = value + 23;
Set_Global_Str("~DebugTab", value);[/code:j4do3h5w]

sort of stuff. Yeah, that’s a bit contrived and could be simplified, but it’s an illustration. :D

Hope this gives you something to start with.