Author Topic: Help with getting information from 2da  (Read 417 times)

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Help with getting information from 2da
« on: September 09, 2010, 12:02:49 am »


               I've always wanted to do something savvy like get information from a custom 2da through a script, for a 2da that I made up.

Can anyone offere information on helping me becoming savvy enough to impliment something like this?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help with getting information from 2da
« Reply #1 on: September 09, 2010, 12:22:24 am »


               Here is everything you need.

// Gets a value from a 2DA file on the server and returns it as a string
// avoid using this function in loops
// - s2DA: the name of the 2da file, 16 chars max
// - sColumn: the name of the column in the 2da
// - nRow: the row in the 2da
// * returns an empty string if file, row, or column not found
string Get2DAString(string s2DA, string sColumn, int nRow)


Documentation: 2DA File Format
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Help with getting information from 2da
« Reply #2 on: September 09, 2010, 06:08:00 am »


               Thanks mate '<img'>
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Help with getting information from 2da
« Reply #3 on: September 09, 2010, 06:45:31 am »


               Ok, I've read up on what you gave me, all of this seems simple enough, how to use the 2DA and how to edit it, and thanks for the information on the function as well..

My next question would be, how can I utilize a 2DA within scripting that can be useful, can you give me an example?
               
               

               


                     Modifié par Genisys, 09 septembre 2010 - 05:45 .
                     
                  


            

Legacy_the.gray.fox

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Help with getting information from 2da
« Reply #4 on: September 09, 2010, 05:06:19 pm »


               

Genisys wrote...

Ok, I've read up on what you gave me, all of this seems simple enough, how to use the 2DA and how to edit it, and thanks for the information on the function as well..

My next question would be, how can I utilize a 2DA within scripting that can be useful, can you give me an example?

Hello.
Are you asking "why would I want to use a custom 2DA I make?"

If yes, see 2DA files as "source of information".
"Any" information.
Generally, the use of a custom 2DA is felt when you have a large dataset to read from.

Suppose that you make your own craft system.
Maybe your rules are that some item types can only receive some itemproperties.
And then, some itemproperties are limited (in quality) dependant on the specific item they are placed upon.
For example: A bonus to Strength could be limited to Gloves and Body Armor.
And the bonus could be further limited to +6 on Gloves, but able to climb to +12 on Body Armor.
And maybe you can not go past +4 Strength if you are not Level 10 at least, and not past +8 Strength if you are not Level 12.
Just an example, and not very complex. But this kind of info is perfect for a 2DA.

If you had it all coded in your scripts, it would be different.
You would have to maintain a bunch of constants inside your scripts, telling what can go where and to which extent. Multiply this for a number of base item types and itemproperties... and you end up with a huge list of constants, going on for pages.
Which is hell to maintain. And is very prone to typo, in spite of all your care.
And regardless, at the minimal change in your constants, you would have to recompile all your scripts.
Sometimes a pure-scripts solution is not even practical, you see.

These problems do not exist with a 2DA resource.
Also, 2DA resources are completely disjoint from the script layer.
So long you preserve their "layout", you can provide several versions of a same 2DA (to implement different rules, for example). And you may switch between them, at runtime, by just changing the name of the 2DA to read from.
Your scripts would need no adaptation, and their performance would not be affected -- as a bonus.


-fox
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Help with getting information from 2da
« Reply #5 on: September 09, 2010, 09:15:19 pm »


               Thanks fox, I've been experimenting with 2das some today, I now see the benefit, because you can store multiple different types of information (by column / row).

However, I suppose my next question would steer me toward using data arrays..

Are Arrays used through scripting much like 2da files (when stored properly that is)?

And if so, then would it be faster to just use a data array set on the module than say, a 2da?
               
               

               


                     Modifié par Genisys, 09 septembre 2010 - 08:15 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help with getting information from 2da
« Reply #6 on: September 09, 2010, 09:50:18 pm »


               

However, I suppose my next question would steer me toward using data arrays..

NWN does not suport arrays in its script language. You can hash thing to together to make them act like an array.   But they are just a similiation of an array.  


Are Arrays used through scripting much like 2da files (when stored properly that is)? 


Are you asking if a file plain-text file that describes a 2-Dimensional Array(2DA) of data,  acts like an array or not? 

 And if so, then would it be faster to just use a data array set on the module than say, a 2da?

By this do you mean a whole bunch of local vars?

Keep in mind that a 2da is only an external data source.   How good or how bad they are is all acording to how you use them. 

Also just because the data is stored in a 2da does not mean you could not have the onload script write contents of the 2da to an object to cache it into memory. 

The truth here is that every situation has its pro's and con's. Part of being a good programer is knowing the system well enough to script twords more of the pro's then the con's and knowing when the cons don't matter vs. when they will tear the whole system down.    the problem is that it is really a case by case judgment call. 
               
               

               


                     Modifié par Lightfoot8, 09 septembre 2010 - 08:51 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Help with getting information from 2da
« Reply #7 on: September 10, 2010, 01:37:27 am »


               Ok, thanks for clarifying that for me some Lightfoot8, that was helpful.



I think I'm going to stick with variables rather than use the 2da, for I don't really need a 2da, when I can just make one include to set / get the information I need by using a loop...