Home AMX User Forum NetLinx Studio

CREATE_LEVEL vs. LEVEL_EVENT

I've red a few posts around CREATE_LEVEL and LEVEL_EVENT...

There are still a few things unclear to me.
- If you use a LEVEL_EVENT, do you absolutely need to declare a CREATE_LEVEL?
- If you declare a CREATE_LEVEL, apparently you don't need the LEVEL_EVENT (unless I've done some magic without knowing it...) - can somebody confirm?

Any additional info on the subject is greatly appreciated.

Paul-Eric

Comments

  • AuserAuser Posts: 506
    Let me preface my answer with a little background. Unlike the value of device channels which can be checked at any time, the value of device levels is transient and can't be queried.

    LEVEL_EVENTS occur when levels change. Trapping this event allows you to perform an action every time a level is updated with a new value. When a level event is fired, the value of the level can be found in the event data item LEVEL.VALUE. Outside of level events, LEVEL.VALUE has no meaning/is out of scope.

    CREATE_LEVEL is a way of associating a variable with a device level. As the value of the device level changes, the variable will be updated to match. CREATE_LEVEL therefore makes it possible to check the value of a device level at any time, not just inside a level event.

    Hope that helps :)
    Pep_SD wrote: »
    - If you use a LEVEL_EVENT, do you absolutely need to declare a CREATE_LEVEL?
    - If you declare a CREATE_LEVEL, apparently you don't need the LEVEL_EVENT (unless I've done some magic without knowing it...) - can somebody confirm?

    The two are completely independent. You can have either in your code without a need to include the other.
  • yuriyuri Posts: 861
    this is actually a good question.

    Back in the days we had to use CREATE_LEVEL, because there was no LEVEL_EVENT.

    At the moment I'm only using LEVEL_EVENT, but come to think of it, CREATE_LEVEL has more advantages...
  • TurnipTruckTurnipTruck Posts: 1,485
    I haven't used CREATE_LEVEL in years. In modern Netlinx programming, I would see no need for it as LEVEL_EVENTs alert you every time there is a level change. The variable that you would associate with a level using a CREATE_LEVEL statement, is easily set in a LEVEL_EVENT, allowing you to work with an accurate value of that variable elsewhere in your program.
  • DHawthorneDHawthorne Posts: 4,584
    I haven't used CREATE_LEVEL in years. In modern Netlinx programming, I would see no need for it as LEVEL_EVENTs alert you every time there is a level change. The variable that you would associate with a level using a CREATE_LEVEL statement, is easily set in a LEVEL_EVENT, allowing you to work with an accurate value of that variable elsewhere in your program.

    It's still very convenient for modules. If you are using a level inside a module, it's LEVEL_EVENT is not accessible to the main program without some kludgy code duplication. Slap a CREATE_LEVEL in it, and pass a variable to the module that is linked to it, and you have full access to the current value without any queries, and without any new event needing to happen. And besides, if all you are doing in a level event is updating a variable, why should you bother, when an internal function can do it for you? I don't see it as obsolete at all.
  • yuriyuri Posts: 861
    I always use a BUTTON_EVENT to capture the level being pressed on the touchpanel, and set a variable high as long as the sliders is held.

    Then I capture the LEVEL_EVENT and check if that variable is high.

    When I use CREATE_LEVEL I would also have to use a BUTTON_EVENT to check when that level has changed, so code-wise it would mean almost no change for me...

    Passing it to a module (device module and Touchpanel module) is a very nice method indeed!
  • Pep_SDPep_SD Posts: 106
    Well, one more time this forum has showed its incredible value all thanks to its invaluable long time members...
    Auser, Yuri, Dave, TurnipTruck thank you for your explanations.

    Definitely teaching a lot and clarifying once and for all.
Sign In or Register to comment.