Home AMX User Forum AMXForums Archive Threads Tips and Tricks

Be CAREFUL using button_event with Arrays!

If you are like me and you use an array of touchpanels, and you also use arrays for channel numbers, be careful. There is a limit to the number of events that can be inserted into the event table this way. I am waiting for confirmation from tech support as to the actual number, but the thinking is that it is around 1000 (probably 1024) even though there is an old tech note (number 383) that indicates the limit to be 4000.

So, if you are having issues where most of the buttons are responding correctly, but some are not, or most of the touch panels work, but not all of them, this may be the cause.

Here is an example:

If you have an array of 40 touch panels(dvTp), and you are using an array of 200 buttons(nButtons), the following will cause problems:

button_event[dvTp,nButtons]{
//do stuff
}

This will cause problems because this statement is adding 40*200 events which is 8000 events. Only the first 1000ish will be added, and no ERROR will be generated during compile. I don't think it will even throw an error during start up.

Don't despair, it is very easy to fix once you are aware of the problem. You only have to break up the button_event line and stack it. You could create ten arrays of buttons (nButtons1_20, nButtons21_40,...) and then declare like this:

button_event[dvTp,nButtons1_20]
button_event[dvTp,nButtons21_40]
.
.
button_event[dvTp,nButtons161_180]
button_event[dvTp,nButtons181_200]{
//do something.
}


This can be a tricky problem to figure out because some touch panels might work completely while others are only partially functional and you will see all of the button pushes come through to the processor, but the code will never be triggered for those events that were never added to the event table.

Jeff

Comments

  • bcirrisibcirrisi Posts: 148
    Good catch, I ran into a similar problem, and ended up breaking it out into individual button presses (that was a long night) for everything. I never really got an answer why. Now I know, "And Knowing is Half the Battle!"
  • ericmedleyericmedley Posts: 4,177
    It's for this reason that I got out of the habit of doing button arrays along the lines of
    My_Device_Buttons[]=
    {1,2,3,4,...   45,46}
    
    And went to more generic mult-purpose button arrays like
    Buttons_1_thru_100[]=
    {01,02,03,04.... ,99,100} 
    
    and then do
    BUTTON_EVENT[dv_World_Domination_Device,Buttons_1_thru_100]
    BUTTON_EVENT[dv_World_Domination_Device,Buttons_101_thru_200]
    BUTTON_EVENT[dv_World_Domination_Device,Buttons_201_thru_300]
    {
    push:
      {
      SEND_COMMAND dv_World_Domination_Minions,'commence plans'
      }
    }
    
  • viningvining Posts: 4,368
    Here's a link from early last year that goes over this issue that my be helpful.

    http://www.amxforums.com/showthread.php?t=3746&highlight=event+table
Sign In or Register to comment.