Difference between revisions of "SValue Loaders"

From Heroes of Hammerwatch wiki
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
SValue loaders are script functions that deserialize sval files at the gamemode initialization step.
+
SValue loaders are script functions that deserialize sval files before the gamemode initialization step. (Before the gamemode object even exists!)
  
 
They are defined in sval files like this:
 
They are defined in sval files like this:
Line 16: Line 16:
 
  }
 
  }
  
You can also specify an <code>order</code> attribute to specify the order in which they are loaded. This is required for sets for example, as they depend on items to exist.
+
Optionally, you can add a string parameter to the loader function in order to get the filename of the sval file which was loaded. For example:
 +
 
 +
void SomeFunction(SValue@ sval, string filename)
 +
{
 +
  string example = GetParamString(UnitPtr(), sval, "example");
 +
  print("SomeFunction example: \"" + example + "\" (from \"" + filename + "\")");
 +
}
 +
 
 +
Note that you may only have 1 of these variations per loader function. It doesn't make much sense to have both. If you do have both, only the function without the filename parameter is called.
 +
 
 +
You can also specify an <code>order</code> attribute to specify the order in which they are loaded. This is required with sets for example, as they depend on items to exist.
  
 
Only one loader tag may exist per file.
 
Only one loader tag may exist per file.
Line 23: Line 33:
 
The following loaders are built-in to Heroes of Hammerwatch:
 
The following loaders are built-in to Heroes of Hammerwatch:
  
* <code>AddItemFile</code> Used for loading item definitions.
+
* <code>AddItemFile</code> Used for loading item definitions. See also [[Custom items]].
 
* <code>AddSetFile</code> Used for loading item set definitions.
 
* <code>AddSetFile</code> Used for loading item set definitions.
 
* <code>AddDrinkFile</code> Used for loading tavern drink definitions.
 
* <code>AddDrinkFile</code> Used for loading tavern drink definitions.
* <code>Materials::LoadDyes</code> Used for loading player dye definitions.
+
* <code>Materials::LoadDyes</code> Used for loading player dye definitions. (B90+)
* <code>Titles::LoadTitles</code> Used for loading class title definitions.
+
* <code>Titles::LoadTitles</code> Used for loading class title definitions. (B90+)
* <code>Upgrades::LoadShop</code> Used for loading upgrade shop definitions.
+
* <code>Upgrades::LoadShop</code> Used for loading upgrade shop definitions. (B90+)
 +
* <code>Fountain::AddWishFile</code> Used for loading fountain wish definitions. (B90+)

Latest revision as of 14:33, 5 October 2018

SValue loaders are script functions that deserialize sval files before the gamemode initialization step. (Before the gamemode object even exists!)

They are defined in sval files like this:

<loader>SomeFunction</loader>
<dict>
  <string name="example">example</string>
</dict>

And loaded by scripts like this:

void SomeFunction(SValue@ sval)
{
  string example = GetParamString(UnitPtr(), sval, "example");
  print("SomeFunction example: \"" + example + "\"");
}

Optionally, you can add a string parameter to the loader function in order to get the filename of the sval file which was loaded. For example:

void SomeFunction(SValue@ sval, string filename)
{
  string example = GetParamString(UnitPtr(), sval, "example");
  print("SomeFunction example: \"" + example + "\" (from \"" + filename + "\")");
}

Note that you may only have 1 of these variations per loader function. It doesn't make much sense to have both. If you do have both, only the function without the filename parameter is called.

You can also specify an order attribute to specify the order in which they are loaded. This is required with sets for example, as they depend on items to exist.

Only one loader tag may exist per file.

Built-in loaders

The following loaders are built-in to Heroes of Hammerwatch:

  • AddItemFile Used for loading item definitions. See also Custom items.
  • AddSetFile Used for loading item set definitions.
  • AddDrinkFile Used for loading tavern drink definitions.
  • Materials::LoadDyes Used for loading player dye definitions. (B90+)
  • Titles::LoadTitles Used for loading class title definitions. (B90+)
  • Upgrades::LoadShop Used for loading upgrade shop definitions. (B90+)
  • Fountain::AddWishFile Used for loading fountain wish definitions. (B90+)