Dynamic Tokens Tips & Tricks

From Stardew Modding Wiki
Jump to navigation Jump to search

This is a collection of various tips & tricks for using Content Patcher's dynamic tokens for increased coding versatility. At their core, dynamic tokens are used for creating a token that changes its value depending on various conditions, which with a little creative thinking can be used for all sorts of situations!

This page assumes that you're already familiar with how to set up a basic dynamic token. If you don't know how to do this, check out the Content Patcher documentation first.

=== When Conditions and True/False Dynamic Tokens

Dynamic tokens can be used in a When check the same as you would use any other CP token, which means that if you want your code to apply only if a specific set of conditions is met (eg, if the player is at the beach in summer OR at the bathhouse in winter OR on Ginger Island during any season), you can set up a dynamic token with "true" and "false" as the values and then add a When check for your token being true or false as needed.

For example:



Order of Dynamic Tokens

When checking which dynamic token value to load, Content Patcher will read them from top to bottom. This means that if you only need a token to be true

true/false order of dynamic tokens setting a fallback token using dynamic tokens as When checks nesting tokens using tokens with Random for consistent checks using tokens with i18n using tokens for repeatable events



Using Dynamic Tokens for Compatibility

Dynamic tokens can be used for easy compatibility with SVE, SVR3, other map replacement mods, or other custom NPC mods with overlapping tile placements. For example, if your character's schedule placement results in them overlapping with something when using SVR3, you can use the following token:

   {
      "Name": "MyCharacterBeachCoordinates",
      "Value": "43 34 2",
   },
   {
      "Name": "MyCharacterBeachCoordinates",
      "Value": "44 34 2",
      "When":
         {
            "HasMod |contains= DaisyNiko.SVR3": true,
         }
   },

Then in your schedule, replace `Beach 43 34 2` with `Beach Template:MyCharacterBeachCoordinates`.


Dynamic Tokens Outfit Tip

If your character has multiple outfits that randomise, setting up that randomisation in a dynamic token rather than in the filepath allows you to then have other parts of your mod reference it. For example, if your character has multiple Spirits' Eve costumes and you'd like to add dialogue to match if they're wearing a specific outfit, you can use the following token:

{
   "Name": "SpiritsEveRandom",
   "Value": "Template:Random: SpiritsEve1, SpiritsEve2",
}, 

and then use

    "When":
    {
       "SpiritsEveRandom |contains= SpiritsEve1": true,
    }

as a condition in your dialogue. This is also useful for co-ordinating overlays.


Mixed Random Seasonal Outfits

If your character has more outfits for one season than others, you can use dynamic tokens in combination with the Random token. For example, if a character has one outfit for spring, fall, and winter but three outfits for summer, you can use the following dynamic token code:

{
   "Name": "MyCharacterSeasonals",
   "Value": "",
},
{
   "Name" : "MyCharacterSeasonals",
   "Value" : "Template:Random: Summer1, Summer2, Summer3",
   "When":
   { 
      "Season": "summer"
   }
}

Then instead of using `MyCharacter_` in your filepath, you would use `MyCharacter_Template:MyCharacterSeasonals`. The dynamic token will fill in the correct season in spring, fall, and winter, and in summer will fill in a random choice of `Summer1`, `Summer2`, or `Summer3`.