Anonymous

Mod Creation/Mod Context API Reference: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
Line 152: Line 152:
const myData = await ctx.loadData('my-data.json');
const myData = await ctx.loadData('my-data.json');
console.log(myData.coolThings); // ['rocks']</nowiki>
console.log(myData.coolThings); // ['rocks']</nowiki>
== Sharing Resources ==
=== share(resourcePath: string): void ===
Shares a packed mod resource for other mods to use.
'''Parameters'''
<code>resourcePath: string</code> The resource path to be shared.
'''Example'''
<nowiki>// manifest.json
{
  "namespace": "helloMelvor"
}</nowiki>
<nowiki>// in JavaScript
ctx.share('my_cool_image.png');
ctx.share('Greeter.mjs');</nowiki>
Then another mod can use the resource anywhere that accepts a mod resource path.
<nowiki>
ctx.getResourceUrl('helloMelvor:my_cool_image.png');
const { Greeter } = await loadModule('helloMelvor:Greeter.mjs');
const greeter = new Greeter();</nowiki>


== Lifecycle Hooks ==
== Lifecycle Hooks ==
91

edits