Environment
In this reference, the environment section specifically refers to the script/system environment that your program is being run on. Examples could include the current line number in the nvgt script being compiled, the operating system being run on or fetching the value of a shell environment variable.
Functions
chdir
Change the current working directory.
bool chdir(const string&in new_directory);
Arguments:
- new_directory: The directory you'd like to change into. Note that this directory must already exist.
Returns:
True if NVGT could set the current working directory to the specified directory; false otherwise.
Example:
void main() {
string directory = input_box("Chdir Test", "Enter a valid path to a directory: ");
// Could we switch to it?
if (chdir (directory))
alert("Success", "That directory is valid and could be switch to.");
else
alert("Failure", "The directory could not be switched to. Check that you have typed the name correctly and that the directory exists.");
}
cwdir
Check the current working directory.
string cwdir();
Returns:
A string containing the current working directory.
Example:
void main() {
alert("Current Working Directory", cwdir());
}
environment_variable_exists
Check if the given environment variable exists.
bool environment_variable_exists(string name);
Arguments:
- string name: the name of the environment variable to check.
Returns:
bool: true if the variable exists, false if not.
Example:
void main() {
bool exists = environment_variable_exists("PATH");
if (exists)
alert("Info", "The PATH variable exists.");
else
alert("Info", "The PATH variable does not exist.");
}
expand_environment_variables
Expand environment variables.
string expand_environment_variables(string variables);
Arguments:
- string variables: A string containing the variable(s) you wish to expand.
Returns:
The expanded environment variable(s) if successful or an empty string if not.
Example:
void main() {
// The end goal here is to obtain the user's home directory on the running system if possible. This logic happens in a below function; here we just display the result.
alert("Result", get_home_directory());
}
string get_home_directory() {
if (system_is_windows) return expand_environment_variables("%USERPROFILE%");
else if (system_is_unix) return expand_environment_variables("$HOME");
else return "Unknown";
}
get_preferred_locales
Get a list of the user's preferred locales.
string[]@ get_preferred_locales();
Returns:
string[]@: a handle to an array containing the locale names (as strings).
Example:
void main() {
string[]@ locales = get_preferred_locales();
string result; // To be shown to the user.
for (uint i = 0; i < locales.length(); i++)
result += locales[i] + ",\n";
// Strip off the trailing comma and new line.
result.trim_whitespace_right_this();
result.erase(result.length() - 1);
alert("Info", "The locales on your system are: " + result);
}
write_environment_variable
Write to an environment variable.
void write_environment_variable(string variable, string value);
Arguments:
string variable: The environment variable you wish to write to.
string value: The value you wish to write to this variable.
Example:
void main() {
write_environment_variable("NVGT_Test_for_docs", "Testing");
alert("Result", read_environment_variable("NVGT_Test_for_docs"));
}
Global Properties
COMMAND_LINE
COMMAND_LINE returns anything that is passed as command line arguments. Note that it returns anything after the application name, and keep in mind that you will have to parse the output yourself (basic example below).
const string COMMAND_LINE;
Example:
void main() {
const string[]@ arguments = COMMAND_LINE.split(" ");
// Did we get any arguments?
if (arguments[0] == "")
alert("Command Line", "No arguments provided.");
else
alert("Command Line", "The first argument is " + arguments[0]);
}
PLATFORM
This property returns a string containing the current platform, such as "Windows NT".
const string PLATFORM;
Example:
void main() {
alert("Your current Platform is", PLATFORM);
}
PLATFORM_ARCHITECTURE
This property returns a string containing the current platform architecture, such as "AMD64".
const string PLATFORM_ARCHITECTURE;
Example:
void main() {
alert("Your current Platform architecture is", PLATFORM_ARCHITECTURE);
}
PLATFORM_DISPLAY_NAME
This property returns a string containing the current platform display name, such as "Windows 8".
const string PLATFORM_DISPLAY_NAME;
Remarks:
Due to a backwards compatibility problem in windows, this function by default will cap out at Windows 8 even if the user is running a newer version of Windows. If determining the most modern windows version on the user's system is important to you, you can create a gamename.exe.manifest file to target your app for modern windows. Here is some microsoft documentation that explains how, you can probably just use the example manifest provided there.
Example:
void main() {
alert("Your current Platform display name is", PLATFORM_DISPLAY_NAME);
}
PLATFORM_VERSION
This property returns a string containing the current platform version, such as "6.2 (Build 9200)".
const string PLATFORM_VERSION;
Example:
void main() {
alert("Your current Platform version is", PLATFORM_VERSION);
}
PROCESSOR_COUNT
This property returns the number of processors on your system. Note that this returns the number of threads, not physical cores.
const uint PROCESSOR_COUNT;
Example:
void main() {
alert("Processor Threads Count", PROCESSOR_COUNT);
}
system_is_unix
This property is true if the application is running on a unix operating system, which in regards to NVGT's platforms is almost everything other than windows.
const bool system_is_unix;
Example:
void main() {
if(system_is_unix)
alert("example", "This application is running on a unix operating system!");
else
alert("example", "This application is probably running on windows, or in any case not a unix operating system");
}
system_is_windows
This property is true if the application is running on a windows operating system.
const bool system_is_windows;
Example:
void main() {
if(system_is_windows)
alert("example", "This application is running on windows!");
else
alert("example", "This application is not running on windows.");
}
system_node_id
This property returns the node ID, or another words, primary MAC address, of your system.
const string system_node_id;
Example:
void main() {
alert("Your system node/host ID is", system_node_id);
}
system_node_name
This property returns the node name, or another word, host name, of your system.
const string system_node_name;
Example:
void main() {
alert("Your system node/host name is", system_node_name);
}