Without this check, tag.GetInt would return 0 if the key did not exist. We then check that the tag has an entry for "QuestsLeft", and if it does, we retrieve that value. Notice how Initialize sets the value to 10, the default value our mod expects. Public override void LoadData( TagCompound tag) If a non-default value is what the mod expects for a missing entry, the following approach can be used: If 0 is the value the mod would expect for a missing entry, this works out well. For example, b = tag.GetInt("b") will return the default value of int if the value does not exist in the TagCompound, and the default value of int is 0. They'd only need to do extra effort if b has a non-default value. For example, if v1.0 of a mod saves only a, but v2.0 saves both a and b, the modder doesn't need to make extra checks validating the value or presence of b for most situations. Using TagCompound helps modders update mods smoothly. Additional support can be implemented by implementing the TagSerializable interface, creating a class that inherits from TagSerializer, or by nesting TagCompounds manually. In addition to the types suggested by the method names, ushort, uint, ulong, Vector2, Vector3, Item, Color, Point16, Rectangle, and EntityDefinition are also supported. See the TagCompound documentation or rely on your IDEs autocomplete to find the method you want. Usually we use the methods like GetInt or GetBool, but we can use Get for Types without specific methods defined. Compatible Data TypesĪll primitive data types are supported as well as byte, int and Lists of other supported data types. Key Ideasīelow are some things to keep in mind as you use TagCompound. ![]() It can be very helpful to view the data in this manner to verify that data is being saved in a manner that makes sense. Please use NBTExplorer to visualize TagCompounds by opening. Like a dictionary, we provide string keys and values of any supported type. If you are familiar with the concepts, thinking of TagCompound as a nestable dictionary or JSON comes pretty close. We use TagCompound in ModSystem, ModItem, ModPlayer, ModNPC, GlobalItem, GlobalNPC, and ModTileEntity. ![]() TagCompound is the data format for custom data saved using tModLoader. ![]() If you need to view the old 1.3 version of this wiki page, click here
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |