Mod Creation/Essentials: Difference between revisions

 
(5 intermediate revisions by the same user not shown)
Line 204: Line 204:


Use <syntaxhighlight lang="js" inline>ctx.loadData</syntaxhighlight> to read and automatically parse a JSON resource.
Use <syntaxhighlight lang="js" inline>ctx.loadData</syntaxhighlight> to read and automatically parse a JSON resource.
''Comments in JSON are purely illustrative and not valid markup''


  <syntaxhighlight lang="js" line>// my-data.json
  <syntaxhighlight lang="js" line>// my-data.json
Line 213: Line 211:
   ]
   ]
}</syntaxhighlight>
}</syntaxhighlight>
<small>''Comments in JSON are purely illustrative and not valid markup''</small>


  <syntaxhighlight lang="js" line>// setup.mjs
  <syntaxhighlight lang="js" line>// setup.mjs
Line 338: Line 338:
   "load": ["path-to-your-data.json"]
   "load": ["path-to-your-data.json"]
}</syntaxhighlight>
}</syntaxhighlight>
<small>''Comments in JSON are purely illustrative and not valid markup''</small>


''or''
''or''
Line 408: Line 410:


''View this topic's relevant API reference here [[Mod Creation/Mod Context API Reference#Mod Settings]].''
''View this topic's relevant API reference here [[Mod Creation/Mod Context API Reference#Mod Settings]].''
{{Disclaimer|When loading your mod as a Local Mod via the Creator Toolkit, the mod must be linked to mod.io and you must have subscribed to and installed the mod via mod.io in order for this data to persist.}}


Your mod can define settings for the player to interact with and visually configure your mod in-game. This feature is accessible through a <code>settings</code> property on the context object. If your mod has any settings defined, your mod will appear in the sidebar under Mod Settings. Clicking this will open up a window with all of your defined settings.
Your mod can define settings for the player to interact with and visually configure your mod in-game. This feature is accessible through a <code>settings</code> property on the context object. If your mod has any settings defined, your mod will appear in the sidebar under Mod Settings. Clicking this will open up a window with all of your defined settings.
Line 542: Line 546:
   "load": "templates.html"
   "load": "templates.html"
}</syntaxhighlight>
}</syntaxhighlight>
<small>''Comments in JSON are purely illustrative and not valid markup''</small>


''or''
''or''
Line 576: Line 582:


''View the account storage's relevant API reference here [[Mod Creation/Mod Context API Reference#Account Data Storage]].''
''View the account storage's relevant API reference here [[Mod Creation/Mod Context API Reference#Account Data Storage]].''
{{Disclaimer|When loading your mod as a Local Mod via the Creator Toolkit, the mod must be linked to mod.io and you must have subscribed to and installed the mod via mod.io in order for this data to persist.}}


There are two options for storing data for your mod that isn't already saved as part of the game or settings: data saved with a character or data saved to the player's account. For most cases, however, character storage should be the preferred location and account storage used sparingly. Both of these stores are available through your mod's context object, as <code>characterStorage</code> and <code>accountStorage</code>, respectively. Aside from where the data is ultimately saved, character and account storage have identical methods and behaviors. Character storage is not available until after a character has been loaded (<code>onCharacterLoaded</code> lifecycle hook).
There are two options for storing data for your mod that isn't already saved as part of the game or settings: data saved with a character or data saved to the player's account. For most cases, however, character storage should be the preferred location and account storage used sparingly. Both of these stores are available through your mod's context object, as <code>characterStorage</code> and <code>accountStorage</code>, respectively. Aside from where the data is ultimately saved, character and account storage have identical methods and behaviors. Character storage is not available until after a character has been loaded (<code>onCharacterLoaded</code> lifecycle hook).
Line 692: Line 700:
   "setup": "setup.mjs"
   "setup": "setup.mjs"
}</syntaxhighlight>
}</syntaxhighlight>
<small>''Comments in JSON are purely illustrative and not valid markup''</small>


  <syntaxhighlight lang="js" line>// setup.mjs
  <syntaxhighlight lang="js" line>// setup.mjs
89

edits