ff_c_cnd_var

Test the value of a variable by de-refencing it.

Scripts

TextAppearsWhen: f_c_cnd_var

Variables

VARIABLE: (string) Name of the variable to check, defaults to VALUE

VALUE: (int) Value to check for, defaults to 0.

OP: operator =, >, <, <=, >=, !=. Default of =.

Source code

// @code
#include "ff_i_core"

// =============================================================================
int StartingConditional()
{
  string sOp = GetScriptParam(OP);
  if (sOp == "")
    sOp = "=";

  string sVariable = GetScriptParam(VARIABLE);
  if (sVariable == "")
  {
    LogError(__FILE__ + ": called with invalid 'VARIABLE' value");
    return FALSE;
  }

  int nValue = StringToInt(GetScriptParam(VALUE));
  int nVariable = GetLocalInt(OBJECT_SELF, sVariable);

  // By default, check equality first
  if (sOp == "=" || sOp == "==")
    return (nVariable == nValue);
  if (sOp == ">")
    return (nVariable > nValue);
  if (sOp == ">=" || sOp == "=>")
    return (nVariable >= nValue);
  if (sOp == "<=" || sOp == "=<")
    return (nVariable <= nValue);
  if (sOp == "<")
    return (nVariable < nValue);
  if (sOp == "!=")
    return (nVariable != nValue);

  if (sOp == "="  || sOp == "==" || sOp == ">" || sOp == ">="  || sOp == "<=" || sOp == "<"  || sOp == "!=")
    {}
  else
    LogError(__FILE__ + ": called with invalid 'OP' value");
  return FALSE;
}