more G-Labs products

Author Topic: Event handling in C#  (Read 1269 times)

February 02, 2015, 09:57:13 PM
Read 1269 times

pim555

  • ****
  • Information
  • Sr. Member
  • Posts: 143
Hello,

I am having trouble in understanding how events are being handled within HG. I have a piece of code that looks for parameters changing:

When.ModuleParameterIsChanging((module, parameter) => {

What is not clear to me is what exactly happens when you return true or false from within this iteration?

Cheers
Pim

February 02, 2015, 11:54:38 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
True stops the iteration, false continues on.

If you have several modules that change at the same time and you want to do something when one of them changes, you would want to use false at least until the module you are searching for has been dealt with.  If you want to be complete, you should continue to return false but you could instead return true to kick out at that point too.  Depends on your goal.

February 03, 2015, 12:05:54 AM
Reply #2

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
hey bkenobi,

that's not the purpose of the return value for ModuleParameterIsChanging event.
If the return value is true, HG will continue propagating the event to other possible listeners (other programs that are listening to the "parameter is changing" event).
If the return value is false, HG will stop propagating that event (other listeners won't receive it).

Cheers,
g.

February 03, 2015, 03:34:16 AM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Wonder if that caused issues when writing the Advance Smart Lights code.  Doh!   :-[

It's working, so I guess it must not be an issue.

February 03, 2015, 06:19:40 AM
Reply #4

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Gene, I guess it's the same way for ModuleParameterChanged. Is it ?