Changes

→‎Unique string IDs: add migrations for pre-1.6 content
Line 130: Line 130:  
* Use namespaced IDs prefixed with your [[Modding:Modder Guide/APIs/Manifest#Basic fields|mod's unique ID]] for all new content. For example, if your mod ID is <code>Example.PufferchickMod</code> and you're adding a pufferchick plushy, your item ID would look like <code>Example.PufferchickMod_PufferchickPlushy</code>. In a [[Modding:Content Patcher|Content Patcher pack]], you can use <code><nowiki>{{ModId}}_PufferchickPlushy</nowiki></code> to insert your mod ID automatically. This eliminates ID conflicts between mods, and makes it easy (for both troubleshooters and mod code) to identify which mod added a particular content. See [[Modding:Common data field types#Unique string ID|the new format docs]] for the recommended format.
 
* Use namespaced IDs prefixed with your [[Modding:Modder Guide/APIs/Manifest#Basic fields|mod's unique ID]] for all new content. For example, if your mod ID is <code>Example.PufferchickMod</code> and you're adding a pufferchick plushy, your item ID would look like <code>Example.PufferchickMod_PufferchickPlushy</code>. In a [[Modding:Content Patcher|Content Patcher pack]], you can use <code><nowiki>{{ModId}}_PufferchickPlushy</nowiki></code> to insert your mod ID automatically. This eliminates ID conflicts between mods, and makes it easy (for both troubleshooters and mod code) to identify which mod added a particular content. See [[Modding:Common data field types#Unique string ID|the new format docs]] for the recommended format.
 
* Only use alphanumeric (a–z, A–Z, 0–9), underscore (<code>_</code>), and dot (<code>.</code>) characters in string IDs. This is important because they're often used in places where some characters have special meaning (like file names or [[#Game state query|game state queries]]).
 
* Only use alphanumeric (a–z, A–Z, 0–9), underscore (<code>_</code>), and dot (<code>.</code>) characters in string IDs. This is important because they're often used in places where some characters have special meaning (like file names or [[#Game state query|game state queries]]).
 +
 +
You can optionally migrate pre-1.6 content to use unique string IDs too, without breaking existing players' saves. This is recommended to reduce mod conflicts and simplify troubleshooting going forward. Here's how to migrate for each data type:
 +
{{collapse|migration steps for pre-1.6 content|content=&#32;
 +
{{{!}} class="wikitable"
 +
{{!}}-
 +
! content type
 +
! how to change IDs
 +
{{!}}-
 +
{{!}} [[Modding:Event data|event IDs]]
 +
{{!}} Use a [[Modding:Trigger actions|trigger action]] to swap the event IDs. For example, using [[Modding:Content Patcher|Content Patcher]]:
 +
<syntaxhighlight lang="js">
 +
// replace OLD_EVENT_ID and NEW_EVENT_ID appropriately
 +
{
 +
    "Action": "EditData",
 +
    "Target": "Data/TriggerActions",
 +
    "Entries": {
 +
        "{{ModId}}_SwapEventId": {
 +
            "Id": "{{ModId}}_SwapEventId",
 +
            "Trigger": "DayStarted",
 +
            "Condition": "PLAYER_HAS_SEEN_EVENT Current OLD_EVENT_ID",
 +
            "Actions": [
 +
                "MarkEventSeen Current OLD_EVENT_ID false",
 +
                "MarkEventSeen Current NEW_EVENT_ID true"
 +
            ]
 +
        }
 +
    }
 +
}
 +
</syntaxhighlight>
 +
{{!}}-
 +
{{!}} [[Modding:Items|item IDs]]
 +
{{!}} {{upcoming|1.6 alpha build 24069}}
 +
 +
Use a [[Modding:Trigger actions|trigger action]] to swap the item IDs. For example, using [[Modding:Content Patcher|Content Patcher]]:
 +
<syntaxhighlight lang="js">
 +
// replace OLD_ITEM_ID (qualified item ID) and NEW_ITEM_ID (unqualified item ID) appropriately
 +
{
 +
    "Action": "EditData",
 +
    "Target": "Data/TriggerActions",
 +
    "Entries": {
 +
        "{{ModId}}_SwapItemId": {
 +
            "Id": "{{ModId}}_SwapItemId",
 +
            "Trigger": "DayStarted",
 +
            "Actions": [
 +
                "SwapItemId OLD_ITEM_ID NEW_ITEM_ID"
 +
            ]
 +
        }
 +
    }
 +
}
 +
</syntaxhighlight>
 +
{{!}}-
 +
{{!}} [[Modding:Location data|location IDs]]
 +
{{!}} Add the old name to the location's <samp>FormerLocationNames</samp> field in <samp>Data/Locations</samp>.
 +
{{!}}-
 +
{{!}} [[Modding:Mail data|mail IDs]]
 +
{{!}} Use a [[Modding:Trigger actions|trigger action]] to swap the mail IDs. For example, using [[Modding:Content Patcher|Content Patcher]]:
 +
<syntaxhighlight lang="js">
 +
// replace OLD_MAIL_ID and NEW_MAIL_ID appropriately
 +
{
 +
    "Action": "EditData",
 +
    "Target": "Data/TriggerActions",
 +
    "Entries": {
 +
        "{{ModId}}_SwapMailId_Mailbox": {
 +
            "Id": "{{ModId}}_SwapMailId_Mailbox",
 +
            "Trigger": "DayStarted",
 +
            "Condition": "PLAYER_HAS_Mail Current OLD_MAIL_ID Mailbox",
 +
            "Actions": [
 +
                "RemoveMail Current OLD_MAIL_ID Mailbox",
 +
                "AddMail Current OLD_MAIL_ID Mailbox"
 +
            ]
 +
        },
 +
        "{{ModId}}_SwapMailId_Received": {
 +
            "Id": "{{ModId}}_SwapMailId_Received",
 +
            "Trigger": "DayStarted",
 +
            "Condition": "PLAYER_HAS_Mail Current OLD_MAIL_ID Received",
 +
            "Actions": [
 +
                "RemoveMail Current OLD_MAIL_ID Received",
 +
                "AddMail Current OLD_MAIL_ID Received"
 +
            ]
 +
        }
 +
    }
 +
}
 +
</syntaxhighlight>
 +
{{!}}-
 +
{{!}} [[Modding:NPC data|NPC internal names]]
 +
{{!}} Add the old name to the NPC's <samp>FormerCharacterNames</samp> field in <samp>Data/Characters</samp>.
 +
{{!}}-
 +
{{!}} [[Modding:Quest data|quest]] and [[Modding:Special orders|special order]] IDs
 +
{{!}} Currently there's no safe way to migrate quest and special order IDs, since removing and readding them will reset any progress the player has made on them.
 +
{{!}}-
 +
{{!}} [[Modding:Recipe data|recipe IDs]]
 +
{{!}} {{upcoming|1.6 alpha build 24069}}
 +
 +
Use a [[Modding:Trigger actions|trigger action]] to swap the recipe IDs.
 +
 +
For example, to migrate a cooking recipe using [[Modding:Content Patcher|Content Patcher]]:
 +
<syntaxhighlight lang="js">
 +
// replace OLD_RECIPE_NAME and NEW_RECIPE_NAME appropriately
 +
{
 +
    "Action": "EditData",
 +
    "Target": "Data/TriggerActions",
 +
    "Entries": {
 +
        "{{ModId}}_SwapRecipeId": {
 +
            "Id": "{{ModId}}_SwapReciped",
 +
            "Trigger": "DayStarted",
 +
            "Condition": 'PLAYER_HAS_COOKING_RECIPE Current "OLD_RECIPE_NAME"',
 +
            "Actions": [
 +
                'MarkCookingRecipeKnown Current "OLD_RECIPE_NAME" false',
 +
                'MarkCookingRecipeKnown Current "NEW_RECIPE_NAME"'
 +
            ]
 +
        }
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 +
To migrate a crafting recipe, change <samp>PLAYER_HAS_COOKING_RECIPE</samp> to <samp>PLAYER_HAS_CRAFTING_RECIPE</samp> and <samp>MarkCookingRecipeKnown</samp> to <samp>MarkCraftingRecipeKnown</samp>.
 +
{{!}}-
 +
{{!}} [[#Custom jukebox tracks|song IDs for jukebox]]
 +
{{!}} You can add the old name to the track's <samp>AlternativeTrackIds</samp> in <samp>Data/JukeboxTracks</samp>. This will keep the old song ID in the player data, but the jukebox will alias it to the new ID.
 +
 +
Alternatively you can use a [[Modding:Trigger actions|trigger action]] to swap the song IDs. For example, using [[Modding:Content Patcher|Content Patcher]]:
 +
<syntaxhighlight lang="js">
 +
// replace OLD_SONG_ID and NEW_SONG_ID appropriately
 +
{
 +
    "Action": "EditData",
 +
    "Target": "Data/TriggerActions",
 +
    "Entries": {
 +
        "{{ModId}}_SwapSongId": {
 +
            "Id": "{{ModId}}_SwapSongId",
 +
            "Trigger": "DayStarted",
 +
            "Condition": "PLAYER_HAS_HEARD_SONG Current OLD_SONG_ID",
 +
            "Actions": [
 +
                "MarkSongHeard Current OLD_SONG_ID false",
 +
                "MarkSongHeard Current NEW_SONG_ID"
 +
            ]
 +
        }
 +
    }
 +
}
 +
</syntaxhighlight>
 +
{{!}}}
 +
}}
    
==What's new for items==
 
==What's new for items==
translators
8,404

edits