Home AMX User Forum NetLinx Studio

Button_event and array definition question

Hello all,

i think i heard about this when i was on programer 1 course but cant recall how it went :(

Anyhow the idea is to either fill array from 1-600, but i dont want 2 type numbers from 1 to 600...
integer some_array[]={1,....,600}
and then do
BUTTON_EVENT[devTp,some_array]
{
PUSH:
{
// something
}
}
OR
do 600 button events ...
BUTTON_EVENT[devTp,1]
... // and then type it fot 599 times :P
BUTTON_EVENT[devTp,600]
{
PUSH:
{
/// something
}
}

So... is there a way to fill the array from 1 to 600?
Or as i have it in my memory 2 make the button_event from 1 to 600 in 3 lines of code:
BUTTON_EVENT[devTP,1]
// some code or something.!?!?!
BUTTON_EVENT[devTP,600]
{
PUSH ...
}

Hope my question is understandable.

Tnx,
Alan

Comments

  • viningvining Posts: 4,368
    if your array is going to be consecutive numbers 1-600 then don't bother with the array at all. The array is really only beneficail in this instance if you using the index position of the array to hold other values that are not the same numbers as their corresponding index position. That's sort or redundant.

    So forget the array, use what ever numbers you want on your buttons and create a single button event:
    BUTTON_EVENT[devTp,0]//0 will catch all button on what ever port devTP is defined.
    
    In your PUSH, HOLD and/or RELEASE handlers you then just use BUTTON.INPUT.CHANNEL instead of GET_LAST to determine the button channel that caused the event.

    Of course if you're hell bent on using the array, then define it with it's desired size and then in define_start run a for loop using the defined length and populate each index position with the index value.
  • DHawthorneDHawthorne Posts: 4,584
    If your question is simply how to avoid typing consecutive numbers quickly, just cut-and-paste *any* numbers until you have as many as you need. Then highlight them all and click the "Sequentially Number Selection" button. I do this all the time to ensure I don't have duplicate device numbers in my declarations ... line them all up and use alt-drag to highlight a column, then hit the button.
  • tnx for your answers they helped but not the answer i was looking for :)

    I remember our tutor at Programer1 course mentioned a command in case we have a situation like this and we want to avoid having loads of BUTTON_EVENT code.

    For example:

    This code:
    BUTTON_EVENT[devTp,1]
    BUTTON_EVENT[devTp,2]
    BUTTON_EVENT[devTp,3]
    BUTTON_EVENT[devTp,4]
    BUTTON_EVENT[devTp,5]
    BUTTON_EVENT[devTp,6]
    BUTTON_EVENT[devTp,7]
    BUTTON_EVENT[devTp,8]
    BUTTON_EVENT[devTp,9]
    BUTTON_EVENT[devTp,10]
    {
    PUSH:
    { 
    // do something
    }
    }
    
    would look like:
    BUTTON_EVENT[devTp,1]
    .. // this two dots is the thing our mentor told us... BUT its not this two dots but something else...
    BUTTON_EVENT[devTp,10]
    {
    PUSH:
    {
    // do something
    }
    }
    

    the two dots in the second part of the code is what im looking for.

    i know in this case i have only 10 BUTTON_EVENT but this is just an example. Im talking here about 64 or more BUTTON_EVENTs...and also i know i can sort this out by making an array with 64 number in and then doing this:
    DEFINE_VARIABLE
    integer some_array[]={1,2,3,4,5,6,7,8,9,10,11,12, till 64}
    integer some_button
    
    DEFINE_EVENT
    BUTTON_EVENT[devTp,some_array]
    {
    PUSH:
    {
    some_button=button.input.channel
    // do something depending on witch some_button pressed...
    }
    }
    

    i really wanna know if im imagining that those two dots have a replacement code or what? :D

    tnx
  • vining wrote: »
    Of course if you're hell bent on using the array, then define it with it's desired size and then in define_start run a for loop using the defined length and populate each index position with the index value.

    Don't forget to do a REBUILD_EVENT after changing that array otherwise your BUTTON_EVENT won't work.
  • ericmedleyericmedley Posts: 4,177
    One thing that I've ran into that is not exactly documented correctly or at all...

    One would think that issuing a REBUILD_EVNET for such-and-so device will only rebuild that event. but that is not what happens. If you issue it, the master will rebuild all events i the code. This can take significantly longer a process that you might imagine. It's just about as long as a reboot. I do not use this command as the benefit does not outweigh the negatives.
  • Don't forget to do a REBUILD_EVENT after changing that array otherwise your BUTTON_EVENT won't work.

    never ever had this probem
  • viningvining Posts: 4,368
    Don't forget to do a REBUILD_EVENT after changing that array otherwise your BUTTON_EVENT won't work.
    Hmmm, that makes me wonder. I'm sure I've tried this a time or two with out rebuilding the tables but I wonder whether it worked or not. My mind ain't what it used to be and even when it was, it wasn't all that good.

    If it wouldn't work is that becuase the working length of the array at complile time is 0, max length would be as defined, or does it need the values in the array in the table building. If it's the latter then you wouldn't be able to dynamically alter the array at runtime with out calling the rebuild event either.

    Like e. said rebuild_event takes a fair amount of time. Last time I tested it took over 30 seconds during which time events are not processed so it's not so bad if it's part of the start up routine cuz that just means it will take a bit longer but at runtime you affectively halt events from being processed for around 30+ seconds so it should be used with caution.
  • Alan: I think you may be getting confused with the shortcut for DEFINE_LATCHING, DEFINE_MUTUALLY_EXCLUSIVE, and DEFINE_TOGGLING:
    The next statement uses the double periods (..) to define a range of VCR channels as latching. In the last statement, the variable VAR1 is defined as latching.
    DEFINE_LATCHING
    [RELAY, SYSTEM_POWER]
    [VCR, PLAY]..[VCR, REWIND]
    VAR1

    I believe the ".." doesn't work anywhere else.

    Eric: The Reference states "REBUILD_EVENT() works on a module-by-module basis (i.e. calling the function in one module does not affect the event table of another module)." Have you found that calling a REBUILD_EVENT inside a module causes the same delay, or are you only calling it in the main program?
  • vining wrote: »
    If it wouldn't work is that becuase the working length of the array at complile time is 0, max length would be as defined, or does it need the values in the array in the table building. If it's the latter then you wouldn't be able to dynamically alter the array at runtime with out calling the rebuild event either.

    #1 is the case:
    DEFINE_VARIABLE
       nButtonArray[10];
    
    
    DEFINE_FUNCTION InitializeButtonArray()
    {
       nButtonArray[1] = 1;
       nButtonArray[2] = 2;
    
       REBUILD_EVENT(); // Doesn't work
    
       SET_LENGTH_ARRAY(nButtonArray, 2);
    
       REBUILD_EVENT(); // Now it works
    
       nButtonArray[1] = 10;
       nButtonArray[2] = 20;
       nButtonArray[3] = 30;
    
       REBUILD_EVENT(); // Only works for 1 & 2
    
       SET_LENGTH_ARRAY(nButtonArray, 3);
    
       REBUILD_EVENT(); // Now it works for 3
    }
    
  • viningvining Posts: 4,368
    Does define start run before the event_tables are built during the boot up? If so you could just run the for loop to populate the array and set_length_array in define_start and then the event_table would be built properly with out the need for REBUILD_EVENT. Just depends on what happens first.

    I know I would have come across this issue at some point and I'm pretty sure I've populated button arrays in def_start before with out the rebuild.
  • viningvining Posts: 4,368
    I had a chance to run a test and as long as the array is populated and the length set in define_start it seems to work fine which to me means that building the event tables are probably the last thing that are done.
    DEFINE_VARIABLE // testing
    
    VOLATILE INTEGER nTestArry[10];
    
    DEFINE_START 	//test items
         
         {
         STACK_VAR INTEGER i;
    
         SEND_STRING 0, "'DEFINE START, INIT nTestArry, length-[ ',itoa(length_array(nTestArry)),' ], max_length-[ ',itoa(max_length_array(nTestArry)),' ] <',ITOA(__LINE__),'>'";
         
         for(i=10; i; i--)
    	  {
    	  nTestArry[i] = i;
    	  }
         SET_LENGTH_ARRAY(nTestArry,10);
         SEND_STRING 0, "'DEFINE START, FINISH INIT nTestArry, length-[ ',itoa(length_array(nTestArry)),' ], max_length-[ ',itoa(max_length_array(nTestArry)),' ] <',ITOA(__LINE__),'>'";
         }
    
    BUTTON_EVENT[vTEST,nTestArry]//0]
         
         {
         PUSH:
    	  {
    	  STACK_VAR INTEGER nBtn;
    	  
    	  nBtn = GET_LAST(nTestArry);
    	  SEND_STRING 0, "'nTestArry, PUSH CHNL-[ ',itoa(nBtn),' ] <',ITOA(__LINE__),'>'";
    	  }
    
    result:
    Line    490 (19:54:48)::  DEFINE START, INIT nTestArry, length-[ 0 ], max_length-[ 10 ] <4368>
    Line    491 (19:54:48)::  DEFINE START, FINISH INIT nTestArry, length-[ 10 ], max_length-[ 10 ] <4375>
    
    Pushing the button using emulate device using the virtual vTest's DPS
    Line    675 (20:00:17)::  nTestArry, PUSH CHNL-[ 1 ] <5298>
    Line    676 (20:00:33)::  nTestArry, PUSH CHNL-[ 8 ] <5298>
    Line    677 (20:00:48)::  nTestArry, PUSH CHNL-[ 1 ] <5298>
    Line    678 (20:00:50)::  nTestArry, PUSH CHNL-[ 2 ] <5298>
    Line    679 (20:00:53)::  nTestArry, PUSH CHNL-[ 3 ] <5298>
    Line    680 (20:00:55)::  nTestArry, PUSH CHNL-[ 4 ] <5298>
    Line    681 (20:00:58)::  nTestArry, PUSH CHNL-[ 5 ] <5298>
    Line    682 (20:01:00)::  nTestArry, PUSH CHNL-[ 6 ] <5298>
    Line    683 (20:01:03)::  nTestArry, PUSH CHNL-[ 7 ] <5298>
    Line    684 (20:01:06)::  nTestArry, PUSH CHNL-[ 8 ] <5298>
    Line    685 (20:01:09)::  nTestArry, PUSH CHNL-[ 9 ] <5298>
    Line    686 (20:01:12)::  nTestArry, PUSH CHNL-[ 10 ] <5298>
    

    No rebuild required.
  • I ran the code you posted and, while the DEFINE_START text printed as you posted, none of the events printed. I noticed you print out the __LINE__ at the end of those messages. The program I ran was only your test code and my first DEFINE_START string was on Line <14> whereas yours began on Line <4368>. Is it possible you have something running somewhere that would've changed how it compiled?

    Here's the whole program I ran. The only difference is the addition of PROGRAM_NAME, DEFINE_DEVICE for vTEST, DEFINE_EVENT before the BUTTON_EVENT, and a "}" to close the BUTTON_EVENT:
    PROGRAM_NAME='VAV Test'
    
    DEFINE_DEVICE
    	vTest = 33001:1:0
    	
    DEFINE_VARIABLE // testing
    
    VOLATILE INTEGER nTestArry[10];
    
    DEFINE_START 	//test items
         
         {
         STACK_VAR INTEGER i;
    
         SEND_STRING 0, "'DEFINE START, INIT nTestArry, length-[ ',itoa(length_array(nTestArry)),' ], max_length-[ ',itoa(max_length_array(nTestArry)),' ] <',ITOA(__LINE__),'>'";
         
         for(i=10; i; i--)
    	  {
    	  nTestArry[i] = i;
    	  }
         SET_LENGTH_ARRAY(nTestArry,10);
         SEND_STRING 0, "'DEFINE START, FINISH INIT nTestArry, length-[ ',itoa(length_array(nTestArry)),' ], max_length-[ ',itoa(max_length_array(nTestArry)),' ] <',ITOA(__LINE__),'>'";
         }
    
    DEFINE_EVENT
    BUTTON_EVENT[vTEST,nTestArry]//0]
         
         {
         PUSH:
    	  {
    	  STACK_VAR INTEGER nBtn;
    	  
    	  nBtn = GET_LAST(nTestArry);
    	  SEND_STRING 0, "'nTestArry, PUSH CHNL-[ ',itoa(nBtn),' ] <',ITOA(__LINE__),'>'";
    	  }
    	  }
    

    Also, here's what the Language Reference guide says about the event table:
    The event table keeps a list of all events in a sorted order to more quickly determine which code needs to be accessed for a giving incoming event. The event table is built before DEFINE_START runs and it not changed anytime after that. As a result, there are certain rules that must be applied to the parameters used in DEFINE_EVENTs.

    Since the event table is built before DEFINE_START, all event parameters must contain the correct information prior to DEFINE_START. This requires that all EVENT parameters must be defined at compile time. In addition, there are "shortcuts" to help fulfill this requirement. Using BUTTON_EVENT as an example, the simplest version of event parameters is a device and channel reference.

    In the following example, the device, dvTp, was defined in the DEFINE_DEVICE section, which has the effect of making it an initialized variable of type DEV, and the channel number was a hard-coded value of 1. :

    DEFINE_DEVICE

    dvTp = 128:1:0

    DEFINE_EVENT

    BUTTON_EVENT[dvTp,1]

    {

    PUSH:

    SEND_STRING 0,'Button 1 of dvTp was pushed'

    }

    Since both of these value were defined at compile time, the event is entered into the event table correctly.

    In the following example, the event will not perform as the previous one did. When the code is compiled, the event parameters are dvTp, which is already assigned, and nMyChannel, which has a value of 0. nMyChannel does not get assigned a value of 1 until DEFINE_START, at which time the event has already been added to the event table.

    DEFINE_DEVICE

    dvTp = 128:1:0

    DEFINE_VARIABLE

    Integer nMyChannel

    DEFINE_START

    nMyChannel = 1

    DEFINE_EVENT

    BUTTON_EVENT[dvTp,nMyChannel]

    {

    PUSH:

    SEND_STRING 0,"'Button ',ITOA(nMyChannel),' of dvTp was pushed'"

    }

    If you were to run this code, you would discover that it did in fact run when button 1 was pushed, leading us to one of the "shortcuts":

    A value of 0 for a Channel or Level Number in a BUTTON_EVENT, CHANNEL_EVENT or LEVEL_EVENT will be interpreted as an event handler for all events of that type from the given device number(s).

    So, the reason the above example runs when button 1 was pushed is that the above example runs when any button on dvTp is pushed. This "shortcut" was added so you could define an event handler for all buttons, channel or levels of a device without having to define a DEVCHAN of DEVLEV containing every value you may want to handle.
  • viningvining Posts: 4,368
    Ok the reference guide makes perfect sense as to why it works. Since the event tables are built before define start runs in this case the array is 0 so it gets built with the wild card, 0, catch all;
    BUTTON_EVENT[vTEST,0]
    
    so it ends up catching everything, not just what the array would eventually hold. This still works with get_last too because get_last isn't specific to the array used to build the table, your just taking the channel that initated the button push and calling a function that sees if there's a match anywhere in the array specified and then that index is returned. Could be any array whether it was used to build the tables or not.

    This basically would work exactly as desired but not as expected and the only real difference is the button_event isn't filtering so that only channels in the array will trigger the push. Any channel on that port will trigger the push handler but only channels that are in the array will return an index number when using get_last, otherwise nBtn would == 0.
  • That makes complete sense, but then why does my 36 line program fails to produce any events whereas your 5300+ line program does?

    My first thoughts go to DEVICE HOLDOFF:
    "Sets the Master to holdoff devices (i.e. does not allow them to report ONLINE) until all objects in the NetLinx program have completed executing the DEFINE_START section.
    If set to ON, any messages to devices in DEFINE_START will be lost, however, this prevents incoming messages being lost in the Master upon startup.
    When DEVICE_HOLDOFF is ON, you must use ONLINE events to trigger device startup SEND_COMMANDs.
    By default, DEVICE HOLDOFF is OFF to maintain compatibility with Axcess systems where devices are initialized in DEFINE_START."

    I doubt DEVICE HOLDOFF has any direct effect on building the event table, but the explanation leads me to wonder if each device reports ONLINE as it's portion of the event table is built. If so, a particularly large program with a large event table may allow a DEFINE_START to run that initializes a variable before its associated portion of the event table is built.

    If you get a chance I'd love to find out what results you get if you only run the minimal code I posted. If not, what processor, firmware, and version of NetLinx Studio are you running?

    I don't want to beat this to death, but when code run by one person runs differently for another, it throws up a big red flag. Those sort of bugs are the ones that have you up at midnight incapable of reproducing the problem or writing some unnecessary "fix".
  • viningvining Posts: 4,368
    Well the plot thickens my good man.

    Running this small code as requested with some slight modifications for added analysis:
    PROGRAM_NAME='MAIN'
    
    
    DEFINE_DEVICE   //VIRTUALS
    
    vTEST               = 33004:1:0;
    
    DEFINE_VARIABLE //testing
    
    NON_VOLATILE INTEGER nMyOneNonVolatileVar;
    VOLATILE INTEGER nTestArry[10];
    VOLATILE INTEGER nTestArry2[10];
    
    DEFINE_START 	//test items
         
         {
         STACK_VAR INTEGER i;
         
         SEND_STRING 0, "'DEFINE START, INIT nTestArry, length-[ ',itoa(length_array(nTestArry)),' ], max_length-[ ',itoa(max_length_array(nTestArry)),' ] <',ITOA(__LINE__),'>'";
         
         for(i=10; i; i--)
    	  {
    	  nTestArry[i] = i;
    	  }
         SET_LENGTH_ARRAY(nTestArry,10);
         SEND_STRING 0, "'DEFINE START, FINISH INIT nTestArry, length-[ ',itoa(length_array(nTestArry)),' ], max_length-[ ',itoa(max_length_array(nTestArry)),' ] <',ITOA(__LINE__),'>'";
         SEND_STRING 0, "'DEFINE START, INIT nTestArry2, length-[ ',itoa(length_array(nTestArry2)),' ], max_length-[ ',itoa(max_length_array(nTestArry2)),' ] <',ITOA(__LINE__),'>'";
         
         nTestArry2[1] = 30;
         nTestArry2[2] = 40;
         nTestArry2[3] = 50;
         nTestArry2[4] = 60;
         nTestArry2[5] = 70;
         nTestArry2[6] = 80;
         nTestArry2[7] = 90;
         nTestArry2[8] = 100;
         nTestArry2[9] = 110;
         nTestArry2[10]= 120;
                      
         SET_LENGTH_ARRAY(nTestArry2,10);
         SEND_STRING 0, "'DEFINE START, FINISH INIT nTestArry, length-[ ',itoa(length_array(nTestArry2)),' ], max_length-[ ',itoa(max_length_array(nTestArry2)),' ] <',ITOA(__LINE__),'>'";
         }
         
    DEFINE_EVENT    //BUTTON_EVENT[vTEST,0]
    
    BUTTON_EVENT[vTEST,nTestArry]//0]
         
         {
         PUSH:
    	  {
    	  STACK_VAR INTEGER nBtn;
    	  
    	  SEND_STRING 0, "'nTestArry, PUSH CHNL-[ ',itoa(BUTTON.INPUT.CHANNEL),' ] <',ITOA(__LINE__),'>'";
    	  nBtn = GET_LAST(nTestArry);
    	  if(nBtn)
    	       {//run code pushed button is in the array
    	       SEND_STRING 0, "'nTestArry, GET_LAST INDEX-[ ',itoa(nBtn),' ] <',ITOA(__LINE__),'>'";
    	       }
    	  else
    	       {//ignore push, button not in the array
    	       SEND_STRING 0, "'nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ ',itoa(nBtn),' ] <',ITOA(__LINE__),'>'";
    	       }
    	  nBtn = GET_LAST(nTestArry2);
    	  if(nBtn)
    	       {//run code pushed button is in the array2
    	       SEND_STRING 0, "'nTestArry2, GET_LAST INDEX-[ ',itoa(nBtn),' ] <',ITOA(__LINE__),'>'";
    	       }
    	  else
    	       {//ignore push, button not in the array2
    	       SEND_STRING 0, "'nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ ',itoa(nBtn),' ] <',ITOA(__LINE__),'>'";
    	       }
    	  }
         }
    
    DEFINE_PROGRAM  //EMPTY
    
    
    Where I'm using
    BUTTON_EVENT[vTEST,nTestArry]//
    
    Which I thought would be built as
    BUTTON_EVENT[vTEST,0]//
    
    I get nothing on any pushes. I even added a non_volatile var just so the system had one since that used to matter and still nothing. Not what I expected at all.

    So I actually changed the button event to
    BUTTON_EVENT[vTEST,0]//
    
    compiled and sent and now pushes work just like the catch all should so the previous method isn't resolving to 0 "catch all". What I didn't expect is that GET_LAST doesn't work.
    Line      1 (19:53:20)::  nTestArry, PUSH CHNL-[ 2 ] <52>
    Line      2 (19:53:20)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line      3 (19:53:20)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    Line      4 (19:53:25)::  nTestArry, PUSH CHNL-[ 5 ] <52>
    Line      5 (19:53:25)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line      6 (19:53:25)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    Line      7 (19:53:29)::  nTestArry, PUSH CHNL-[ 10 ] <52>
    Line      8 (19:53:29)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line      9 (19:53:29)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    Line     10 (19:53:33)::  nTestArry, PUSH CHNL-[ 30 ] <52>
    Line     11 (19:53:33)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line     12 (19:53:33)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    Line     13 (19:53:37)::  nTestArry, PUSH CHNL-[ 35 ] <52>
    Line     14 (19:53:37)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line     15 (19:53:37)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    Line     16 (19:53:41)::  nTestArry, PUSH CHNL-[ 20 ] <52>
    Line     17 (19:53:41)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line     18 (19:53:41)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    Line     19 (19:53:45)::  nTestArry, PUSH CHNL-[ 60 ] <52>
    Line     20 (19:53:45)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line     21 (19:53:45)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    Line     22 (19:53:51)::  nTestArry, PUSH CHNL-[ 100 ] <52>
    Line     23 (19:53:51)::  nTestArry, CHNL NOT FOUND IN ARRAY, nBtn-[ 0 ] <60>
    Line     24 (19:53:51)::  nTestArry2, CHNL NOT FOUND IN ARRAY2, nBtn-[ 0 ] <69>
    
    so GET_LAST must be tied to the event table and since there is no array built into the table it doesn't work. Everything I thought in my last post is wrong which goes back to your question of why it worked in my larger system's code. I don't use the hold-off command anywhere, ever, so this is a bit of a puzzle.

    The system starts up so fast I can't get diagnostics to run in time to see the send string 0's I have in define start but in debug I can see the arrays have been populated.

    This is not what I expected to see!
  • ericmedleyericmedley Posts: 4,177
    Get last doesn't work but perhaps button.input.channel? Then you could build your own get_last.
  • viningvining Posts: 4,368
    ericmedley wrote: »
    Get last doesn't work but perhaps button.input.channel? Then you could build your own get_last.
    This isn't really about getting code to work but understanding why it is or isn't working and how the button event table is being built. But yes B.I.C works when the table is built using 0 so creating your own get_last function would be easy to accomplish the OPs goal. But....

    Why did it work differently in a large file than it did in the small file.

    Why if the array isn't defined until after the table was built didn't it resolve to 0 "catch all" when built since when built the array lenght would have been 0. An un-initialized var would have initialized the event table with 0, catching all. Does an un-initialized array differ in the way the table is built. Does it cause an error so the table isn't built or built with out the ability to catch any channels since the array wasn't defined, if so why didn't it default to 0 and catch all? And most curiously why did it work in the large file and not the small?
  • viningvining Posts: 4,368
    Ok, back to the large file, same code.

    Now I can catch the send_string 0' in def start again.
    Line     10 (07:15:38)::  DEFINE START, INIT nTestArry, length-[ 0 ], max_length-[ 10 ] <4369>
    Line     11 (07:15:38)::  DEFINE START, FINISH INIT nTestArry, length-[ 10 ], max_length-[ 10 ] <4376>
    Line     12 (07:15:38)::  DEFINE START, INIT nTestArry2, length-[ 0 ], max_length-[ 10 ] <4377>
    Line     13 (07:15:38)::  DEFINE START, FINISH INIT nTestArry, length-[ 10 ], max_length-[ 10 ] <4391>
    
    Out of curiosity I tried:
    BUTTON_EVENT[vTEST,nTestArry]//0]//
    BUTTON_EVENT[vTEST,nTestArry2] 
    
    with very odd results. The channels pushed would be filtered by these 2 arrays so anything that is not in either array doesn't get through but get_last results are a bit odd.
    Line     23 (07:21:14)::  nTestArry, PUSH CHNL-[ 30 ] <5313>
    Line     24 (07:21:14)::  nTestArry, GET_LAST INDEX-[ 3 ] <5317>
    Line     25 (07:21:14)::  nTestArry2, GET_LAST INDEX-[ 1 ] <5326>
    Line     26 (07:22:09)::  nTestArry, PUSH CHNL-[ 4 ] <5313>
    Line     27 (07:22:09)::  nTestArry, GET_LAST INDEX-[ 4 ] <5317>
    Line     28 (07:22:09)::  nTestArry2, GET_LAST INDEX-[ 1 ] <5326>
    Line     29 (07:25:38)::  nTestArry, PUSH CHNL-[ 60 ] <5313>
    Line     30 (07:25:38)::  nTestArry, GET_LAST INDEX-[ 4 ] <5317>
    Line     31 (07:25:38)::  nTestArry2, GET_LAST INDEX-[ 4 ] <5326>
    Line     59 (07:26:03)::  nTestArry, PUSH CHNL-[ 70 ] <5313>
    Line     60 (07:26:03)::  nTestArry, GET_LAST INDEX-[ 4 ] <5317>
    Line     61 (07:26:03)::  nTestArry2, GET_LAST INDEX-[ 5 ] <5326>
    
    it seems if the channel doesn't match anything in the array it returns the last known match to the specific array. I tried this out of curiosity (using 2 arrays), don't know why anyone would want to do this but I tried anyway. This is obviously attributable to having 2 arrays defined in the event_table and otherwise get_last would work properly since channels that didn't match the array wouldn't get through in the first place.

    So back on point, it seems on a large system there is some sort of delay or ......... ya know, I bet somewhere in my code in this big file I'm using rebuild_event somewhere else and it must be rebuilding all the tables like e. originally said. Maybe NJ's original assumption that it is limited to scope it true in a module but not if it's in the main or any include. I thought the instructions for it said it only affected the event tables related to items with in the braces where it's called so maybe this isn't exactly the case. I'm pretty sure any time I use it it's properly braced and isolated, usually after set_virual_ports or channels, etc.

    So I gonna assume it works in the big file because of a rebuild_event called elsewhere in the main or includes and that an un-defined array that's not later intialized and rebuilt will not work and will not default to 0 catch all like would be the case with a regular var that's not defined. Now I need to verify I actually do have a rebuild_event some where in this code ro it's back to the drawing board.
  • VAV,
    I've messed around with some test code and your assumptions seem to be correct with what I've found.
    1. An array length of 0 equaled no events.
    2. REBUILD_EVENT only affected the module it was called in.
    3. ALL events were rebuilt regardless of scope or which array was just modified. As long as an array had a SET_LENGTH > 0, it's event table was rebuilt.
Sign In or Register to comment.