ff_i_flags

Object and module flag functions.

Flags are string-typed local variables that encode boolean or integer values as "T", "F", "DEFAULT", "INHERIT", or an integer string.

GetObjectFlag resolves the value walking up from the object to its area then to the module when the value is "INHERIT".

GetModuleFlag reads from the module with a cache layer to avoid repeated variable lookups.

int GetObjectFlag(object oObject, string sVariable, int nDefault = FALSE)
Parameters:
  • oObject – An object.

  • sVariable – Name of the local string variable holding “T”/”F” (or synonyms).

  • nDefault – Value returned when the variable is absent. Defaults to FALSE.

  • sVariable – Name of the variable.

  • nDefault – Default value.

Return the value of a flag: A flag is a string variable, not an int, on a object that is either “Y” or “N”.

int GetModuleFlag(string sVariable, int nDefault)
Parameters:
  • sVariable – Name of the variable on the module.

  • nDefault – Value returned when absent.

Check a variable for “T” or “F”, or return default on empty.

Source code

// @code

#include "ff_i_console"
#include "ff_i_string"
#include "ff_i_vars"

#include "nwnx_object"


// -----------------------------------------------------------------------------

//! @brief Return the value of a flag: A flag is a string variable, not an int, on a object that is either "Y" or "N".
//! @param oObject An object.
//! @param sVariable Name of the local string variable holding "T"/"F" (or synonyms).
//! @param nDefault Value returned when the variable is absent. Defaults to FALSE.
//! @param sVariable Name of the variable.
//! @param nDefault  Default value.
// TODO/FIXME: Add cache?
int GetObjectFlag(object oObject, string sVariable, int nDefault = FALSE);
int GetObjectFlag(object oObject, string sVariable, int nDefault = FALSE)
{
  return GetLocalBoolean(oObject, sVariable, nDefault);
}


// -----------------------------------------------------------------------------

// TODO/FIXME: Add cache?
//! @brief Check a variable for "T" or "F", or return default on empty.
//! @param sVariable Name of the variable on the module.
//! @param nDefault Value returned when absent.
int GetModuleFlag(string sVariable, int nDefault);
int GetModuleFlag(string sVariable, int nDefault)
{
  object oModule = GetModule();
  return GetObjectFlag(oModule, sVariable, nDefault);
}