GLOBAL SITE AUSTRALIAN SITE

Conditional Registering of Event Handlers | EdPy Programming | Forum

Please consider registering
guest

Log In Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Topic3
Conditional Registering of Event Handlers
July 27, 2018
3:25 pm
Mark
New Member
Members
Forum Posts: 1
Member Since:
July 27, 2018
sp_UserOfflineSmall Offline

I have been trying to register an event handle only if a particular value is true (see example below)

def tuneFinished1():
        for tf in range(40):
                Ed.LeftLed(Ed.ON)
                Ed.TimeWait(100, Ed.TIME_MILLISECONDS)
                Ed.LeftLed(Ed.OFF)
                Ed.TimeWait(100, Ed.TIME_MILLISECONDS)

event1=0
if event1 == 1:
        Ed.RegisterEventHandler(Ed.EVENT_TUNE_FINISHED, “tuneFinished1”)

However I find that handler is registered no matter what the value of the event1 variable is set to. 

Is it possible to conditionally register an event handler?

July 30, 2018
10:04 am
Ben
Admin
Forum Posts: 179
Member Since:
August 24, 2015
sp_UserOfflineSmall Offline

Hi Mark

No, it is not possible to conditionally register an event handlers, because Ed.RegisterEventHandler() is a special function.

Ed.RegisterEventHandler() is only used by the compiler to set up the event handler, Edison cannot setup event handlers while running a program.

So the compiler pulls out the Ed.RegisterEventHandler() during the first pass and compiles it, then compiles the rest of the code in the second pass.

You can get a similar behaviour by using a variable as a flag:

Ed.RegisterEventHandler(Ed.EVENT_TUNE_FINISHED, “tuneFinished1”)
useEvent = 0

def tuneFinished1():
    if useEvent=1:
        for tf in range(40):
            Ed.LeftLed(Ed.ON)
            Ed.TimeWait(100, Ed.TIME_MILLISECONDS)
            Ed.LeftLed(Ed.OFF)
            Ed.TimeWait(100, Ed.TIME_MILLISECONDS)

event1=0
if event1 == 1:
    useEvent = 1

This allows you to conditionally activate and deactivate an event.

  • Keep up with Edison

    Sign up for our newsletter to get all things Edison delivered straight to your inbox.

  • This field is for validation purposes and should be left unchanged.

Heads up

The Australian Federal Parliament has passed a law that extends goods and services tax (GST) to low value imports of physical goods imported by consumers from 1 July 2018.

This means that all customers purchasing Edison robots and accessories with an Australian shipping address must now pay GST. The GST will be automatically added to your purchase and show as a line item on your invoice.

We've detected that you are in Australia, so we wanted to let you know that we have changed your settings to view our Australian site, which displays GST inclusive pricing.

You can change back to the GLOBAL SITE at any time using the link in the top left of the page.

OK got it!    Take me to the GLOBAL SITE instead

Country

Pin It on Pinterest

Share This