How to initialize global variable?

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #844

    I have confusion about how to create and initialize Global Variables.

    str mystring “HELLO”;

    Apparently this doesn’t do what I’m expecting it to do. I’m trying to create a global string variable named ‘mystring’ and initialize it to “HELLO”.

    Instead I think this creates a global variable named HELLO, does not initialize it, and creates an alias name ‘mystring’ which points to the string variable named HELLO. This is all very confusing.

    So my question now is, how do I initialize a global variable? There must be another line of code I need to add, but I don’t know where to put it.


    The global { } definition is used to create aliases for global variables which can then be access like normal variables in macros. I already discussed how to read and write globals via aliases in another posting

    One method for initializing system wide global variables is to use the Config\Startup.cfg file. This file is basically an Update script (Update.s) which is run every time Multi-Edit is started or switches sessions. The following is what you would add to this file to set a global string and integer.

    GStr mystring My string
    GInt myint 5


    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.


    I hit Preview instead of Submit, and wandered off for a meeting… :D

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.