Editing Key Value Pairs
Key Value pairs are the easiest to edit and create, mostly because they treat all of their values exactly the same. One example in v16+ is in
if line[ /^([^=]+)=(.*)$/ ]
for i in 0...value.length
This is the important part, that does the actual interpreting. The very first line checks if the line even is a key value pair, by matching the regular expression to a string that ends with an equal sign, the equal sign itself, and all of the values after the equal sign. The two brackets save the key and the value to built-in variables, and value is turned into a string. Here, since all the values are just numbers, it just loops over each string in value, cleans up any extra spaces and saves it as an integer.
The last two lines involve saving the key as an item instead, since these are berry plants, and the next adds the key value pair to the array that gets into
Key Value pairs are easily extended with additional values, as the game will access only the needed information while the game is running. To see how those are read by the game, look at
Editing Comma Separated Values
Comma separated values are used in almost all of the compiler's scripts involving PBS files, and it is valuable to understand how they work. This example will be from
pbCompileMoves as it uses
pbGetCsvRecord and a large variety of the codes from above as well.
The first thing to note, is the schema
"vnsxueeuuuxiss". It matches with the following arguments, which is in fact the default values. The
nil values coincide with codes that don't require an argument, so the integers, strings, etc. The two "e"s match up with
PBTypes is the representation of every single type that's defined, while the array will map to 0, 1, or 2 depending on what was written in that position. If you aren't using enums, you don't need the additional items in that array.
Sections are very similar to Comma Separated Values with a key difference, it stores the key in a hash map which has the array from above containing the schema. Every Section type has two hash maps right at the very top called
optionaltypes. Required types require those keys to be present in the section while optional types are optional. This does introduce a new feature, setting of the byte offset or array index when stored in a data file. This example is from
pbCompilePokemonData, though some keys were trimmed.
Pokemon data is one of those that has its own version of the
pbGetCsvRecord. Some new codes that you might have not seen include the * code, which repeats the following codes until it no longer fits the schema. The rest are mostly exclusive to this method and mainly deal with varying amounts of bytes to be saved.