91
edits
Buttchouda (talk | contribs) |
Buttchouda (talk | contribs) |
||
Line 843: | Line 843: | ||
ctx.patch(TownshipResource, 'amount').get(() => 999999);</nowiki> | ctx.patch(TownshipResource, 'amount').get(() => 999999);</nowiki> | ||
==== PropertyPatch.set(setter: (value: any) => void): void ==== | ==== PropertyPatch.set(setter: (o: (value: any) => void, value: any) => void): void ==== | ||
Execute the provided function when a setter property is accessed. | Execute the provided function when a setter property is accessed. | ||
Line 849: | Line 849: | ||
'''Parameters''' | '''Parameters''' | ||
<code>setter: (value: any) => any</code> The | <code>setter: (o: (value: any) => void, value: any) => void</code> The setter function to be executed. The first parameter, <code>o</code>, is a reference to the setter method being replaced, which is either a previous setter patch or the original setter method. The second parameter, <code>value</code>, contains the value being set. | ||
'''Example''' | '''Example''' | ||
<nowiki> | <nowiki>// Sorry, there aren't many setters in the game to use for a practical example | ||
// Sorry, there aren't many setters in the game to use for a | // Doubles whatever resource amount is being set | ||
ctx.patch(TownshipResource, 'amount').set( | ctx.patch(TownshipResource, 'amount').set((o, amount) => o(amount * 2)); | ||
// While in-game | |||
game.township.resources.getObjectByID('melvorF:Wood').amount = 1000; | |||
game.township.renderQueue.resourceAmounts = true; | |||
// 2000 wood is available</nowiki> | |||
==== PropertyPatch.replace(getter?: () => any, setter?: (value: any) => void): void ==== | ==== PropertyPatch.replace(getter?: () => any, setter?: (value: any) => void): void ==== |
edits