Skip to content

function toggleEvent

Note

By default every event is toggled on (enabled).

This function will toggle event (enable or disable it globally). By toggling event off, you can completely disable certain event from calling it's handlers.
Original: toggleEvent

Declaration

def toggleEvent(name : str, toggle : bool)

Parameters

  • str name: the name of the event
  • bool toggle: false if you want to disable the event, otherwise true.

Usage

import g2o

@g2o.event('onTime')
def onTimeEvt(**kwargs):
    print('Calling only once')
    g2o.toggleEvent('onTime', false)
Source code in src/pyg2o/functions/event.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def toggleEvent(name : str, toggle : bool):
    '''
    !!! note
        By default every event is toggled `on` (enabled).

    This function will toggle event (enable or disable it globally). By toggling event off, you can completely disable certain event from calling it's handlers.
    Original: [toggleEvent](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/toggleEvent/)

    ## Declaration
    ```python
    def toggleEvent(name : str, toggle : bool)
    ```

    ## Parameters
    * `str` **name**: the name of the event
    * `bool` **toggle**: `false` if you want to disable the event, otherwise true.

    ## Usage
    ```python
    import g2o

    @g2o.event('onTime')
    def onTimeEvt(**kwargs):
        print('Calling only once')
        g2o.toggleEvent('onTime', false)
    ```
    '''
    if not toggle and name not in disabledEventList:
        disabledEventList.append(name)
    elif toggle and name in disabledEventList:
        disabledEventList.remove(name)