Using a variable named 'grp' on a SHAC = bad

Discussion in 'C-Bus Automation Controllers' started by ssaunders, May 24, 2022.

  1. ssaunders

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    231
    Likes Received:
    31
    Location:
    Melbourne
    I could find no posts regarding folks stepping on this particular rake and getting smacked in the face by its handle.

    In hindsight it was a silly mistake.

    I inadvertantly declared a numeric variable called 'grp' in a script, and things went absolutely fine for weeks until... I tried to use Get/SetUserParam in that script.

    Then suddenly:

    Code:
    Library cbuslogic:0: attempt to index global 'grp' (a number value)
    stack traceback:
     Library cbuslogic: in function 'SetUserParam'
    It took me an awkwardly long while to work out what was happening, as an identical SetUserParam command was executing successfully in this script's init code.

    The reserved global 'grp' was being clobbered by my script elsewhere in a function. My 'grp', which was a number, should have been declared as 'local' or had its name changed altogeter. The functions Get/SetUserParam, and I'm sure loads more depend on the global 'grp' being left unmolested, and fair enough.

    D'oh. I won't make that mistake again.
     
    ssaunders, May 24, 2022
    #1
  2. ssaunders

    Dasman

    Joined:
    May 5, 2011
    Messages:
    37
    Likes Received:
    5
    Location:
    Adelaide
    Definitely come across this one a few times, so you arent alone.

    You are right though, grp is a global variable which has some functionality behind it.

    For example I use grp.getvalue(event.dst) to get the value of any group address regardless of the application. Its a sneaky little work around for not having to bother detecting the application and use the appropriate C-Bus function
     
    Dasman, Jun 1, 2022
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.