Tutorial 6

Tutorial 6: Form re-use

So you've written some forms and they're starting to get a little long and complicated. If they contain sections which are identical, you can separate that section out into another form and use includeForm to include it in the other forms. For example:

Form "Interrupts":

kick-ifTargetIsCasting-ifNotTargetIs=Stunned
gouge-ifTargetIsCasting-ifNotInFrontAttackJustFailed-ifNotTargetIs=Stunned
ks-ifTargetIsCasting=Greater Heal,Prayer of Healing,Healing Touch,Holy Light,Healing Wave,Chain Heal-ifNotTargetIs=Stunned
blind-ifTargetIsCasting=Greater Heal,Prayer of Healing,Healing Touch,Holy Light,Healing Wave,Chain Heal-ifNotTargetIs=Stunned

Form "FrontAttack":

includeForm=Interrupts
riposte
evisc-5cp
ss

Form "BehindAttack":

includeForm=Interrupts
evisc-5cp
bs

This will include the Interrupts form at the beginning of both the FrontAttack and BehindAttack forms as if you had copy and pasted it in there. When you change the contents of the Interrupts form, it will automatically update the FrontAttack and BehindAttack forms to include the new version.

Note: Be careful that you don't try to include a form into itself, or try to include a form which includes the first form (A includes B includes A). Those will cause a stack overflow error because they're infinite recursion loops.

Now perhaps you have some actions that you only want to perform under certain conditions but don't want the whole list of actions to be checked every time you press your LazyScript button. If we look at the previous example, we can see that ifTargetIsCasting is a criteria common to all of the actions in the Interrupts form. Using callForm we could rewrite the previous example like so:

Form "Interrupts":

kick
gouge-ifNotInFrontAttackJustFailed
ks-ifTargetIsCasting=Greater Heal,Prayer of Healing,Healing Touch,Holy Light,Healing Wave,Chain Heal
blind-ifTargetIsCasting=Greater Heal,Prayer of Healing,Healing Touch,Holy Light,Healing Wave,Chain Heal

Form "FrontAttack":

callForm=Interrupts-ifTargetIsCasting-ifNotTargetIs=Stunned
riposte
evisc-5cp
ss

Form "BehindAttack":

callForm=Interrupts-ifTargetIsCasting-ifNotTargetIs=Stunned
evisc-5cp
bs

With these changes, when you execute FrontAttack or BehindAttack, it will call the Interrupts form only if the target is casting and not stunned. So if the target is not casting, it won't even check any of the actions/criteria in the Interrupts form.