Get2DAString(string, string, int)

Retrieves a string value from a *.2da file on a server.

string Get2DAString(
    string s2DA,
    string sColumn,
    int nRow
);

Parameters

s2DA

Name of the *.2DA file on the server.

sColumn

Name of the column within the *.2DA file.

nRow

Row number within the *.2DA file.


Description

Returns the value of a string in the given location of a specified *.2da file. Returns an empty string if file, column, or row is not found. Returns "" (empty string) for "****" entries in the *.2da.

Get2DAString loads data dynamically into the game, meaning you can change the *.2da while the game is running and calling the function will always return the current values from the *.2da.



Remarks

Do not use this function within a loop because it is slow; looping through 50 rows can take a few seconds, but a few rows (10 or less) might be okay.

Do not prefix your own *.2da files with the prefix "des_".

The maximum length for a *.2da file is 16 characters. If you specify a longer file name, the function will fail without warning.


Known Bugs

The maximum length of a field within a *.2da file is 267 characters. Anything longer than that will cause NWN to crash.


Version

1.31

Example

// return TRUE if weapon does bludgeoning damage
// Uses Get2DAString, avoid to use in loops! 
int GetDoesBludgeoningDamage(object oWeapon)
{
  int nBaseType = GetBaseType(oWeapon);
  return (StringToInt(Get2DAString("baseitems","WeaponType",nBaseType) == 2);
  // 2 = bludgeoning
}

See Also

categories: Database Functions | Get Data Functions | String Functions


 author: Charles Feduke, additional contributor(s): Georg Zoeller, Bob Flaherty
 Send comments on this topic.