Reference 〉Function

Helipad.addHook( str place, func(mixed) func, bool prioritize = False )

Inserts a function into designated places in the model’s logic. See the Hooks Reference for a complete list of possible hooks and the function signatures necessary to use them.

This method is aliased by the @model.hook function decorator, which is the preferred way to hook functions.

Parameters

  • place str, required

    The name of the hook in which to insert the function.

  • func func(mixed), required

    The function to be hooked in place. The function's signature will depend on the hook. See the Hooks Reference.

  • prioritize bool, optional

    Run the hook before all existing hooks in the queue. Note this parameter does not affect the position of the hook with respect to future functions added to the same hook.

    Default value: False

Notes and Examples

  1. charwick

    Aug 06, 2020 at 3:43

    This snippet hooks the defined function into the modelStep hook.

    from helipad import Helipad
    heli = Helipad()
    
    def modelStepFunc(model, stage):
    	#This function will run at each stage of each step of the model
    	pass
    heli.addHook('modelStep', modelStepFunc)

    This is equivalent to adding the @heli.hook('modelStep') to the line above the function.

  2. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History