Reference 〉 Decorator

@Helipad.hook(placestrNone, prioritizeboolFalse)

A function decorator used to insert 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 decorator can be used bare (i.e. without parentheses) on a function whose name corresponds to a hook name. It can also take one argument, the name of the hook, to insert a function with any name into a designated hook. Further keyword arguments (e.g. prioritize) are passed to Hooks.add().

Parameters

  • place str, optional

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

    Default value: None

  • 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:49

    This snippet hooks the defined function into the modelStep hook. Note that it does not need parentheses if the function name corresponds to a hook name.

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

    The function can also be named anything at all, passing a hook name argument to the decorator.

    @heli.hook('match')
    def fight(agents, primitive, model, stage):
    	if agents[0].strength > agents[1].strength:
    		agents[1].die()
    		for good, n in agents[1].stocks:
    			agents[0].stocks[good] += n
  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