Difference between revisions of "Get2DAString"

From NWN Lexicon
Jump to: navigation, search
(Created page with " =Get2DAString(string, string, int)= Retrieves a string value from a *.2da file on a server. string  Get2DAString(      string  ...")
 
Line 7: Line 7:
 
Retrieves a string value from a *.2da file on a server.
 
Retrieves a string value from a *.2da file on a server.
  
 +
<nwscript>
 
  [[string | string ]] Get2DAString(
 
  [[string | string ]] Get2DAString(
 
      [[string | string ]] s2DA,
 
      [[string | string ]] s2DA,
Line 12: Line 13:
 
      [[int | int ]] nRow
 
      [[int | int ]] nRow
 
  );
 
  );
 +
</nwscript>
  
 
====Parameters====
 
====Parameters====
Line 53: Line 55:
 
====Example====
 
====Example====
  
<font color="#007f00">// Return TRUE if weapon does bludgeoning damage
+
<nwscript>
  </font><font color="#007f00">// Uses Get2DAString
+
// Return TRUE if weapon does bludgeoning damage
  </font>
+
  // Uses Get2DAString
  <font color="#0000ff">int</font> GetDoesBludgeoningDamage(<font color="#0000ff">object</font> oWeapon)
+
   
 +
  int GetDoesBludgeoningDamage(object oWeapon)
 
  {
 
  {
     <font color="#0000ff">int</font> nBaseType = GetBaseType(oWeapon);
+
     int nBaseType = GetBaseType(oWeapon);
     <font color="#0000ff">return</font> (StringToInt(Get2DAString(<font color="#00007f">"baseitems"</font>,<font color="#00007f">"WeaponType"</font>,nBaseType) == <font color="#7f007f">2</font>);
+
     return (StringToInt(Get2DAString("baseitems","WeaponType",nBaseType) == 2);
     <font color="#007f00">// 2 = bludgeoning
+
     // 2 = bludgeoning
  </font>}
+
  }
 +
</nwscript>
  
 
====See Also====
 
====See Also====

Revision as of 20:37, 25 August 2012



Get2DAString(string, string, int)

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

 [[string | string ]] Get2DAString(
     [[string | string ]] s2DA,
     [[string | string ]] sColumn,
     [[int | 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() now is cached the first time it is called, into the memory of the computer. Basically - you can now use this function in a loop with a lot less noticable loss of speed!

Obviously now you cannot change 2da files dynamically out of game, and see changes in-game.



Remarks

You can now loop using this function. It will now work (or should work) as fast as the game would itself getting information from a 2da file. Likely, there now should be no noticable loss of speed compared to pre-1.64. If there is loss of speed - it'll be greatly improved upon pre-1.64.

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.

Although not a bug, the changes to this in 1.64 means you cannot change a 2da file out-of-game, and it change the results in-game. This is intended 1.64 behaviour.


Version

1.64

Example

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

See Also



 author: Charles Feduke, editor: Jasperre, additional contributor(s): Georg Zoeller, Bob Flaherty, Jasperre