Global Variables

For common settings across recipes. Global variables can be accessed through the 'gvar' variable. Its highly recommended to only use these when absolutely necessary. If settings for use within the same recipe need to be stored. Then please do so in the recipe "content" or "temp" folder location. Through the file read and write functions.

These global variables are viewable and changeable by the user in settings. But the average user will not be able to navigate these settings on their own. You should add your own dialog combined with these functions;

getGlobalVar
gets the value of a global variable from the app settings NOTE: you can also use gvar.NAME to access the variable as shortcut
removeGlobalVar
removes the value of a global variable from the app settings NOTE: this will only affect gvar.NAME on reload of the recipe
setGlobalVar
sets the value of a global variable in the app settings

gvar structure

You can also access variables that define the environment through the gvar structure. ie gvar.pss to get a string that can be used as path separator on the current platform. As these are different on Windows and macOS. Same applies to the app, document and data folders. Where the `globalApplicationsDirectoryX86` is windows specific for the 32bits program files folder on a 64bit system.

echo(objectToString(gvar));

output:

{
  "recipe_name": "default", // display name
  "recipe_path": "C:\\Users\\Jorn\\AppData\\Roaming\\magnetron.dev_data\\recipes\\default.js", // absolute path to the current recipe
  "devmode": 1, // running in dev or app
  "JUCEVersion": "JUCE v6.1.3", // provided for internal use
  "start_epoch": 1658543009, // the start time of the current process
  "userHomeDirectory": "C:\\Users\\...",
  "userApplicationDataDirectory": "C:\\Users\\...\\AppData\\Roaming",
  "commonApplicationDataDirectory": "C:\\ProgramData",
  "userDocumentsDirectory": "C:\\Users\\...\\Documents",
  "commonDocumentsDirectory": "C:\\Users\\Public\\Documents",
  "globalApplicationsDirectory": "C:\\Program Files",
  "globalApplicationsDirectoryX86": "C:\\Program Files (x86)",
  "isWindows": 1, // non zero if Windows, or use "isMacOS"
  "Windows": "10", // OS version, or use "MacOS"
  "OSname": "Windows 10", // OS display name
  "is64bit": 1, // non zero if 64 bit platform
  "UserName": "Jorn", // OS username
  "ComputerName": "DESKTOP", // network name
  "UserLanguage": "en", // OS language
  "UserRegion": "NL", // OS region
  "DisplayLanguage": "en-US", // OS display language
  "DeviceDescription": "Windows (Desktop)", // OS Device Description
  "DeviceManufacturer": "", // Device Manufacturer
  "DeviceIdentifiers": [ // a semi unique number to identify this OS environment
    "50000001bfe9a"
  ],
  "NumCpus": 8, // total threads
  "NumPhysicalCpus": 4, // physical cpu count
  "CpuMegahertz": 3472,
  "CpuVendor": "GenuineIntel",
  "CpuModel": "Intel(R) Core(TM) i7",
  "MemorySizeMB": 16267,
  "PathSeparatorString": "\\", // string that can be used as path separator on the current platform
  "pss": "\\", // string that can be used as path separator on the current platform
  "flavour": 1, // non zero if the flavour was valid
  "debug": 1 // non zero if safety dialogs are enabled
}

examples

// Add and remove a persistent global variable in the app settings
function TestGlobalVar()
{
    echo(getGlobalVar("test_var"));
    if (setGlobalVar("test_var", "1234567890")) // asks for confirmation
    {
        echo(getGlobalVar("test_var"));
        sleepMs(1000);
        removeGlobalVar("test_var"); // asks for confirmation
    }
}

icon names

Icons in the file list are used for user feedback purposes with setFileIcon(). The name used as argument will be auto completed, so you can try your luck with a random short input. But an array with all available icon names is available as global variable. You can print the complete list with:

echo("icon names [" + icon_names.size + "]: " + objectToString(icon_names));

folders

Access the folders from the user application settings through the global folders object. Use these read-only values to make the interaction more predicatible for the user.

echo("app folders:" + objectToString(folders));

folders.home;
folders.output;
folders.temp;
folders.recipes;
folders.content;
folders.bin;

also see allowed folders for more