Skip to content

Commit

Permalink
docs/events.rst - Clarify trigger usage
Browse files Browse the repository at this point in the history
Make wording clear that trigger pattern used to prevent duplicate calls of sheduled function. Avoid word 'once', as schedule_once() make it confusing.
  • Loading branch information
Fak3 committed Jul 15, 2016
1 parent 1144a83 commit 65b2926
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions doc/sources/guide/events.rst
Expand Up @@ -134,14 +134,16 @@ every second.
Trigger events
~~~~~~~~~~~~~~

If you want to schedule a function to be called only once for the next frame,
like a trigger, you might be tempted to achieve that like so::
Sometimes you may want to schedule a function to be called only once for the next
frame, preventing duplicate calls. You might be tempted to achieve that like so::

# before
# First, shedule once.
event = Clock.schedule_once(my_callback, 0)
# and then later
# Then, in another place you will have to unschedule first
# to avoid duplicate call. Then you can shedule again.
Clock.unschedule(event)
Clock.schedule_once(my_callback, 0)
event = Clock.schedule_once(my_callback, 0)

This way of programming a trigger is expensive, since you'll always call
unschedule, even if the event has already completed. In addition, a new event is
Expand Down

0 comments on commit 65b2926

Please sign in to comment.