Libraries‎ > ‎Library‎ > ‎User input‎ > ‎

Button

BehaviourComposer: ignore everything before this.

Begin micro-behaviour:

Begin description:

Create a button with associated micro-behaviours.

End description

Button

Begin NetLogo code:

substitute-text-area-for upper-left-corner-x 5  
substitute-text-area-for upper-left-corner-y 225
substitute-text-area-for lower-right-corner-x 107
substitute-text-area-for lower-right-corner-y 255
substitute-text-area-for button-label Add Behaviours
substitute-text-area-for recipients all-individuals
substitute-text-area-for keyboard-shortcut A
substitute-text-area-for repeat-forever false
add-button 
  'upper-left-corner-x' 'upper-left-corner-y' ; upper left corner 
  'lower-right-corner-x' 'lower-right-corner-y' ; lower right corner
  'button-label' ; label (cannot contain single quotes)
  'add-behaviours-to recipients 
                     list-of-micro-behaviours "Behaviours added by button" []' ; action
  'keyboard-shortcut' ; keyboard shortcut
  'repeat-forever' ; if true then this button will repeat its action forever

End NetLogo code

Variants

All the parameters can be changed by editing the text areas. If you don't want a keyboard shortcut then remove the last line of code. 

How this works

This creates a NetLogo button. The last parameter, the action, is available to micro-behaviours as the value of the button-command variable.

Related micro-behaviours

If this button changes the heading or position of the agent then add  Display current turtle state at the end of the list of button behavioursto ensure that the agent's appearance is updated when the button is clicked regardless of whether the model is running or not. 

History

Button was implemented by Ken Kahn.

BehaviourComposer: ignore everything after this.

Comments