Anonymous

Mod Creation/Mod Context API Reference: Difference between revisions

From Melvor Idle
→‎MethodPatch.after(hook: (returnValue: any, ...args: any) => any | void): void: Make it more obvious that the after function has one more argument than the original call (the return type)
(Add clarification that traditional function expressions are more suitable and preferred to arrow function expressions when patching methods and updated examples.)
(→‎MethodPatch.after(hook: (returnValue: any, ...args: any) => any | void): void: Make it more obvious that the after function has one more argument than the original call (the return type))
 
Line 836: Line 836:


  <syntaxhighlight lang="js" line>// The player never misses an attack
  <syntaxhighlight lang="js" line>// The player never misses an attack
ctx.patch(Player, 'rollToHit').after(function (willHit) {
// Patching: rollToHit(target: Character, attack: SpecialAttack): boolean;
   if (!willHit) console.log('A miss? I think not!');
ctx.patch(Player, 'rollToHit').after(function(willHit, target, attack) {
   if (!willHit) {
    console.log(`A miss? With ${attack.name}? Against ${target.noun.plain}? I think not!`);
  }
   return true;
   return true;
});</syntaxhighlight>
})</syntaxhighlight>


==== MethodPatch.replace(replacement: (replacedMethod: (...args: any) => any, ...args: any) => any): void ====
==== MethodPatch.replace(replacement: (replacedMethod: (...args: any) => any, ...args: any) => any): void ====
56

edits