Anonymous

Mod Creation/Mod Context API Reference: Difference between revisions

From Melvor Idle
Line 828: Line 828:
// Replacement #1</nowiki>
// Replacement #1</nowiki>


==== PropertyPatch.get(getter: () => any): void ====
==== PropertyPatch.get(getter: (o: () => any) => any): void ====


Execute the provided function and return the return value when a getter property is accessed.
Execute the provided function and return the return value when a getter property is accessed.
Line 834: Line 834:
'''Parameters'''
'''Parameters'''


<code>getter: () => any</code> The getter function to be executed.
<code>getter: (o: () => any) => any</code> The getter function to be executed. The parameter <code>o</code> is a reference to the getter method being replaced, which is either a previous getter patch or the original getter method.


'''Example'''
'''Example'''


  <nowiki>// Unlimited township resources
  <nowiki>// Effectively double available Township resources
ctx.patch(TownshipResource, 'amount').get((o) => o() * 2);
// Or more practically, make resources unlimited
ctx.patch(TownshipResource, 'amount').get(() => 999999);</nowiki>
ctx.patch(TownshipResource, 'amount').get(() => 999999);</nowiki>


91

edits