Difference between revisions of "Get2DAString"

From NWN Lexicon
Jump to: navigation, search
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
{{DISPLAYTITLE:Get2DAString(string, string, int)}}__NOTOC__Retrieves a string value from a *.2da file on a server.
 +
<nwscript>
 +
string Get2DAString(
 +
    string s2DA,
 +
    string sColumn,
 +
    int nRow
 +
);
 +
</nwscript>
  
 +
===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===
  
=Get2DAString(string, string, int)=
+
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.
 
 
Retrieves a string value from a *.2da file on a server.
 
 
 
<nwscript>
 
[[string | string ]] Get2DAString(
 
    [[string | string ]] s2DA,
 
    [[string | string ]] sColumn,
 
    [[int | int ]] nRow
 
);
 
</nwscript>
 
 
 
====Parameters====
 
  
''s2DA''
+
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 noticeable loss of speed!
  
Name of the *.2DA file on the server.
+
Obviously now you cannot change 2da files dynamically out of game, and see changes in-game.
  
''sColumn''
 
  
Name of the column within the *.2DA file.
+
===Remarks===
  
''nRow''
+
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 noticeable loss of speed compared to pre-1.64. If there is loss of speed - it'll be greatly improved upon pre-1.64.
  
Row number within the *.2DA file.
+
Do not prefix your own *.2da files with the prefix "des_".
  
<br />
+
The maximum length for a *.2da file is 16 characters. If you specify a longer file name, the function will fail without warning.
  
====Description====
+
Most game 2da files are up to 65535 entries as of NWN:EE, some exceptions from clippy:
  
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. <br /><br /> 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! <br /><br /> Obviously now you cannot change 2da files dynamically out of game, and see changes in-game.
+
* classes.2da is up to 254 entries
 +
* skills.2da also goes up to 255 max, though there's a few quirks there
 +
* spells.2da goes up to 65535, but in 1.69 any spells above 4096 would not be usable from the radial menu (fixed in NWN:EE)
 +
* races.2da may be capped up to 255 max
 +
* body parts are limited to 255 for network reasons
  
<br /><br />
+
A few things go even above 65535 up to 4 billion, but 65535 is quite a high limit regardless of a custom or game used 2da file.
  
====Remarks====
+
If you create custom 2da files there is the settings in settings.tml that relate to this function:
  
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. <br /><br /> Do not prefix your own *.2da files with the prefix "des_". <br /><br /> The maximum length for a *.2da file is 16 characters. If you specify a longer file name, the function will fail without warning.
+
* 2da-engine-cache-size = 11
 +
* 2da-user-cache-size = 10
  
<br />
+
If you use more than this amount of custom 2da files it would be recommended to up this number appropriately since it's still stuck in 2002-era values.
  
====Known Bugs====
+
===Known Bugs===
  
The maximum length of a field within a *.2da file is 267 characters. Anything longer than that will cause NWN to crash. <br /><br /> 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.
+
The maximum length of a field within a *.2da file is 267 characters. Anything longer than that will cause NWN to crash.
  
<br />
+
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 behavior.
  
====Version====
 
  
 +
===Version===
 
1.64
 
1.64
  
====Example====
+
===Example===
 +
<nwscript>
 +
// Return TRUE if weapon does bludgeoning damage
 +
// Uses Get2DAString
  
<nwscript>
+
int GetDoesBludgeoningDamage(object oWeapon)
// Return TRUE if weapon does bludgeoning damage
+
{
// Uses Get2DAString
+
    int nBaseType = GetBaseItemType(oWeapon);
+
    return (StringToInt(Get2DAString("baseitems", "WeaponType", nBaseType)) == 2);
int GetDoesBludgeoningDamage(object oWeapon)
+
    // 2 = bludgeoning
{
+
}
    int nBaseType = GetBaseType(oWeapon);
 
    return (StringToInt(Get2DAString("baseitems","WeaponType",nBaseType) == 2);
 
    // 2 = bludgeoning
 
}
 
 
</nwscript>
 
</nwscript>
  
====See Also====
+
===See Also===
 
 
 
{| class="seealso"
 
{| class="seealso"
 
|}
 
|}
  
<br />
 
 
----
 
----
<font color="gray">  author: Charles Feduke, editor: Jasperre, additional contributor(s): Georg Zoeller, Bob Flaherty, Jasperre</font><br />  <br />
+
<font color="gray">  author: Charles Feduke, editor: Jasperre, additional contributor(s): Georg Zoeller, Bob Flaherty, Jasperre</font>
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:Database_Functions]]
 
[[Category:Database_Functions]]
 
[[Category:Get_Data_Functions]]
 
[[Category:Get_Data_Functions]]
 
[[Category:String_Functions]]
 
[[Category:String_Functions]]

Latest revision as of 16:31, 14 April 2021

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() 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 noticeable 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 noticeable 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.

Most game 2da files are up to 65535 entries as of NWN:EE, some exceptions from clippy:

  • classes.2da is up to 254 entries
  • skills.2da also goes up to 255 max, though there's a few quirks there
  • spells.2da goes up to 65535, but in 1.69 any spells above 4096 would not be usable from the radial menu (fixed in NWN:EE)
  • races.2da may be capped up to 255 max
  • body parts are limited to 255 for network reasons

A few things go even above 65535 up to 4 billion, but 65535 is quite a high limit regardless of a custom or game used 2da file.

If you create custom 2da files there is the settings in settings.tml that relate to this function:

  • 2da-engine-cache-size = 11
  • 2da-user-cache-size = 10

If you use more than this amount of custom 2da files it would be recommended to up this number appropriately since it's still stuck in 2002-era values.

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 behavior.


Version

1.64

Example

// Return TRUE if weapon does bludgeoning damage
// Uses Get2DAString
 
int GetDoesBludgeoningDamage(object oWeapon)
{
    int nBaseType = GetBaseItemType(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