Anonymous

Mod Creation/Mod Context API Reference: Difference between revisions

From Melvor Idle
Line 755: Line 755:


== Exposing Properties and Methods (Mod API) ==
== Exposing Properties and Methods (Mod API) ==
You may want to allow other mods to be able to interact or integrate with your mod through an API you define. To do so, the recommended approach is through the <code>api</code> method on the context object. After defining an API using the method below, other mods can access it through the global <code>mod.api['your_mods_namespace']</code> object.
You may want to allow other mods to be able to interact or integrate with your mod through an API you define. To do so, the recommended approach is through the <code>api</code> method on the context object. After defining an API using the method below, other mods can access it through the global <code>mod.api['your_mods_namespace']</code> object.


=== <code>api(endpoints?: object): object</code> ===
=== api(endpoints?: object): object ===
 
Specify properties and methods to expose on the global <code>mod.api['your_mods_namespace']</code> object. Can be called multiple times to append more endpoints.
Specify properties and methods to expose on the global <code>mod.api['your_mods_namespace']</code> object. Can be called multiple times to append more endpoints.


Line 769: Line 771:


'''Example'''
'''Example'''
  <nowiki>// manifest.json
  <nowiki>// manifest.json
{
{
Line 783: Line 786:


Other mods would then be able to interact with your API:  
Other mods would then be able to interact with your API:  
  <nowiki>// some other mod
  <nowiki>// some other mod
mod.api.helloWorld.greet('Melvor'); // Hello, Melvor!</nowiki>
mod.api.helloWorld.greet('Melvor'); // Hello, Melvor!</nowiki>
91

edits