REBUILD_EVENTS()

dtuckerdtucker Junior MemberPosts: 7
I am having some difficulty with REBUILD_EVENTS(). I want to have a CHANNEL_EVENT that operates on an array of devchan elements, like so:
DEFINE_VARIABLE

devchan devchanElements[10];
integer count;

DEFINE_EVENTS

CHANNEL_EVENT [devchanElements]
{
  ON:
  {
    send_string 0, "'Channel ',itoa(channel.channel),' was turned on.'"
  }
}

And I would like to make changes to that array at runtime:
DEFINE_FUNCTION AddDevChan(dev d, integer c)
{
  count = count + 1;
  devchanElements[count].DEVICE = d;
  devchanElements[count].CHANNEL = c;
  REBUILD_EVENT();
}
I would expect that when I call the AddDevChan that channel events that occur on that device and channel will be raised. But that is not happening. It seems my REBUILD_EVENT() method is not updating the event as needed.

Does anybody see what I might be doing wrong? Is it clear what I am trying to accomplish?

Comments

  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    It looks like the length of the DevChan array is 0 since the DevChan array is not initialized during the declaration and I don?t see any code that sets the length after you add to the array. When you set individual elements of any array the elements will get set but the length will not change.

    Try changing this:
    DEFINE_FUNCTION AddDevChan(dev d, integer c)
    {
      count = count + 1;
      devchanElements[count].DEVICE = d;
      devchanElements[count].CHANNEL = c;
      REBUILD_EVENT();
    }
    

    To this:
    DEFINE_FUNCTION AddDevChan(dev d, integer c)
    {
      count = count + 1;
      devchanElements[count].DEVICE = d;
      devchanElements[count].CHANNEL = c;
      [b]SET_LENGTH_ARRAY(devchanElements,count)[/b]
      REBUILD_EVENT();
    }
    

    And you should be good to go.

    HTH
  • KimKim Junior Member Posts: 51
    hello Dave
    Consider, that function REBUILD_EVENT in each module operates independently... And in occasion of a code I would write so:
    DEFINE_FUNCTION AddDevChan(dev d, integer c)
    {
        stack_var integer count;
        count = length_array(devchanElements);
        if(count<10) //10 is declared length
        {
    	SET_LENGTH_ARRAY(devchanElements,count+1);
    	devchanElements[count+1].DEVICE = d;
    	devchanElements[count+1].CHANNEL = c;
    	REBUILD_EVENT();
        }
        else
        {
    	send_string 0,"'Error index to large!'";
        }
    }
    
  • GSLogicGSLogic Original Member Posts: 562
    Can someone explain the purpose for using REBUILD_EVENT()
  • viningvining X Member Posts: 4,353
    GSLogic wrote:
    Can someone explain the purpose for using REBUILD_EVENT()
    I'd like to know too! Just didn't have the balls to ask.
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    GSLogic wrote: »
    Can someone explain the purpose for using REBUILD_EVENT()
    I?ve used REBUILD_EVENT() in two different scenarios and they are:

    1) As a typing shortcut for large button arrays as shown in example 1.

    2) As a way to pass one button array into a module and then split the array into multiple button arrays as shown in example 2. I could just as easily pass in multiple button arrays to begin with and many times I do but sometimes I think the one array method is cleaner.

    I?m sure there are much better uses for REBUILD_EVENT() and I wish I knew what they are because I feel like I?m missing out on something. :) REBUID_EVENT() users please chime in.


    Example 1: Typing shortcut.

    Instead of doing something like this:
    DEFINE_DEVICE
    
    dvTP	= 10001:1:0
    
    DEFINE_CONSTANT
    
    INTEGER nMaxLights	= 380
    
    INTEGER nLightBtns[]	= {
    
       1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,
       1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,
       1021,1022,1023,1024,1025,1026,1027,1028,1029,1030,
       1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,
       1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,
       1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,
       1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,
       1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,
       1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,
       1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,
       1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,
       1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,
       1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,
       1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,
       1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,
       1151,1152,1153,1154,1155,1156,1157,1158,1159,1160,
       1161,1162,1163,1164,1165,1166,1167,1168,1169,1170,
       1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,
       1181,1182,1183,1184,1185,1186,1187,1188,1189,1190,
       1191,1192,1193,1194,1195,1196,1197,1198,1199,1200,
       1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,
       1211,1212,1213,1214,1215,1216,1217,1218,1219,1220,
       1221,1222,1223,1224,1225,1226,1227,1228,1229,1230,
       1231,1232,1233,1234,1235,1236,1237,1238,1239,1240,
       1241,1242,1243,1244,1245,1246,1247,1248,1249,1250,
       1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,
       1261,1262,1263,1264,1265,1266,1267,1268,1269,1270,
       1271,1272,1273,1274,1275,1276,1277,1278,1279,1280,
       1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,
       1291,1292,1293,1294,1295,1296,1297,1298,1299,1300,
       1301,1302,1303,1304,1305,1306,1307,1308,1309,1310,
       1311,1312,1313,1314,1315,1316,1317,1318,1319,1320,
       1321,1322,1323,1324,1325,1326,1327,1328,1329,1330,
       1331,1332,1333,1334,1335,1336,1337,1338,1339,1340,
       1341,1342,1343,1344,1345,1346,1347,1348,1349,1350,
       1351,1352,1353,1354,1355,1356,1357,1358,1359,1360,
       1361,1362,1363,1364,1365,1366,1367,1368,1369,1370,
       1371,1372,1373,1374,1375,1376,1377,1378,1379,1380
    
    }
    
    DEFINE_START
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,nLightBtns] { 
    
       PUSH: {
    
       
       }
    }
    
    

    I use REBUILD_EVENT() like this:
    DEFINE_DEVICE
    
    dvTP	= 10001:1:0
    
    DEFINE_CONSTANT
    
    INTEGER nMaxLights	= 380
    INTEGER nLightOffset	= 1000
    
    DEFINE_VARIABLE
    
    VOLATILE INTEGER 	nLightBtns[nMaxLights]
    
    DEFINE_FUNCTION fnInitLights () {
    
       INTEGER x
       
       FOR (x=1; x<=nMaxLights; x++) {
          nLightBtns[x] = nLightOffset+x
       }
       
       SET_LENGTH_ARRAY(nLightBtns,nMaxLights)   
       [b]REBUILD_EVENT()[/b]
       
    }
    
    DEFINE_START
    
    fnInitLights()
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,nLightBtns] { 
    
       PUSH: {
    
       
       }
    }
    
    


    Example 2: Split button array passed into a module.

    Include file:
    DEFINE_DEVICE
    
    dviPod		= 5001:2:0
    
    dvjPodTP1	= 10001:6:0
    dvjPodTP2	= 10002:6:0
    
    vdvjPodTP	= 33001:1:0
    
    DEFINE_VARIABLE
    
    VOLATILE  DEV	dvjPodTPs[]		= {dvjPodTP1,dvjPodTP2}
    
    VOLATILE  INTEGER njPodSongLvl		= 1
    
    VOLATILE  INTEGER njPodMaxSearchLines[10] = {1,2,3,4,5,6,7,8,19,10}
    
    VOLATILE INTEGER njPodTPBtns[] = {
    
       18,//  Refresh            1
       19,//  Play/Pause         2
       20,//  Skip Fwd           3
       21,//  Skip Rev           4
       22,//  Scan Fwd           5
       23,//  Scan Rev           6
       24,//  Menu               7
       25,//  Category Playlist  8
       26,//  Category Artist    9
       27,//  Category Album    10
       28,//  Category Genre    11
       29,//  Category Song     12
       30,//  Category Composer 13
       31,//  Repeat            14
       32,//  Shuffle           15
       33,//  Connect/Reset.....16
       34,//  Search Page Up....17
       35,//  Search Page Down..18
       36,//  Search Line 1.....19
       37,//  Search Line 2.....20
       38,//  Search Line 3.....21
       39,//  Search Line 4.....22
       40,//  Search Line 5.....23
       41,//  Search Line 6 ....24
       42,//  Search Line 7.....25
       43,//  Search Line 8.....26
       44,//  Search Line 9.....27
       45,//  Search Line 10....28
       46,//  Play Selection ...29
       99,//  Online Indicator..30
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999 //NOT USED - RESERVED FOR FUTURE USE
    
    }
    
    VOLATILE INTEGER njPodTPTxt[] = {
    
      101,//  Song Title.........1
      102,//  Artist Name........2
      103,//  Album Name.........3
      104,//  Song Position......4
      105,//  iPod Name..........5
      106,//  Now Playing x/y....6
      107,//  Menu Level.........7
      108,//  Search Page x of y.8
       31,//  Repeat.............9
       32,//  Shuffle...........10
       36,//  Search Line 1.....11
       37,//  Search Line 2.....12
       38,//  Search Line 3.....13
       39,//  Search Line 4.....14
       40,//  Search Line 5.....15
       41,//  Search Line 6 ....16
       42,//  Search Line 7.....17
       43,//  Search Line 8.....18
       44,//  Search Line 9.....19
       45,//  Search Line 10....20
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999,//NOT USED - RESERVED FOR FUTURE USE
       9999 //NOT USED - RESERVED FOR FUTURE USE
    }
    
    DEFINE_START
    
    DEFINE_MODULE 'jPod_jMod' mdljPod(dviPod,
    				    vdvjPodTP,
    				    dvjPodTPs,
    				    njPodSongLvl,
    				    njPodTPBtns,
    				    njPodTPTxt,
    				    njPodMaxSearchLines[8])
    
    

    Module file with REBUILD_EVENT():
    MODULE_NAME='jPod_jMod' (DEV dviPod, 
    			   DEV vdvTP, 
    			   DEV dvTP[],
    			   INTEGER nSongPosLvl,
    			   INTEGER nTPBtns[],
    			   INTEGER nTPTxt[],
    			   INTEGER nMaxSearchLines)
    
    DEFINE_VARIABLE
    
    VOLATILE INTEGER		nCategoryBtns[6]
    VOLATILE INTEGER		nSearchLineBtns[10]
    
    DEFINE_FUNCTION fnInit() {
    
       nCategoryBtns[1]	= nTPBtns[8]
       nCategoryBtns[2]	= nTPBtns[9]
       nCategoryBtns[3]	= nTPBtns[10]
       nCategoryBtns[4]	= nTPBtns[11]
       nCategoryBtns[5]	= nTPBtns[12]
       nCategoryBtns[6]	= nTPBtns[13]
       SET_LENGTH_ARRAY(nCategoryBtns,6)
       
       nSearchLineBtns[1]	= nTPBtns[19]
       nSearchLineBtns[2]	= nTPBtns[20]
       nSearchLineBtns[3]	= nTPBtns[21]
       nSearchLineBtns[4]	= nTPBtns[22]
       nSearchLineBtns[5]	= nTPBtns[23]
       nSearchLineBtns[6]	= nTPBtns[24]
       nSearchLineBtns[7]	= nTPBtns[25]
       nSearchLineBtns[8]	= nTPBtns[26]
       nSearchLineBtns[9]	= nTPBtns[27]
       nSearchLineBtns[10]= nTPBtns[28]
       SET_LENGTH_ARRAY(nSearchLineBtns,10)
    
       [b]REBUILD_EVENT()[/b]
    }
    
    DEFINE_START
    
    fnInit()
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,nCategoryBtns] {
    
       PUSH: {
    
       }
    }
    
    BUTTON_EVENT[dvTP,nSearchLineBtns] {
    
       PUSH: {
       
       }
    }
    
    
  • viningvining X Member Posts: 4,353
    Joe wrote:
    DEFINE_FUNCTION fnInitLights () {
    
       INTEGER x
       
       FOR (x=1; x<=nMaxLights; x++) {
          nLightBtns[x] = nLightOffset+x
       }
       
       SET_LENGTH_ARRAY(nLightBtns,nMaxLights)   
       REBUILD_EVENT()
       
    }
    

    Joe this example is virtually identical to the example in the NS2 help files but I still don't get why you need:
    SET_LENGTH_ARRAY(nLightBtns,nMaxLights)   
       REBUILD_EVENT()
    
    
    and what this does.

    When the button array is initialize during compiling the array is filled w/ zeros and in define_start you call the function fnInitLights () which loads your values so what does the set_lenght_array and rebuild_event actually do for you. I am so not getting this! :confused:
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    vining wrote: »
    Joe this example is virtually identical to the example in the NS2 help files but I still don't get why you need:
    SET_LENGTH_ARRAY(nLightBtns,nMaxLights)   
       REBUILD_EVENT()
    
    
    and what this does.

    When the button array is initialize during compiling the array is filled w/ zeros and in define_start you call the function fnInitLights () which loads your values so what does the set_lenght_array and rebuild_event actually do for you. I am so not getting this! :confused:
    vining,

    Let?s start backwards and begin with REBUILD_EVENT(). First off, the event table is built at compile time. Let?s say we have the following code:
    DEFINE_DEVICE
    
    dvTP1 = 10001:1:0
    dvTP2 = 10002:1:0
    dvTP3 = 10003:1:0
    
    DEFINE_VARIABLE
    
    DEV	dvTPs[]	= {dvTP1,dvTP2,dvTP3}
    
    INTEGER nSomeButtons[] = {1,2,3}
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTPs,nSomeButtons] {
    
       PUSH: {
       
       }
    }
    

    When buttons 1, 2, or 3 are pushed for dvTP1, dvTP2, or dvTP3, the BUTTON_EVENT fires. Fair enough.

    Now let?s say during runtime we want to change the nSomeButtons array to something like this:

    nSomeButtons = ?4,5,6?

    If we want the BUTTON_EVENT to fire with these new button values then we have to call REBUILD_EVENT() so that the event table is reconstructed. Probably a more practical example is subtracting or adding back into the DEV array and then calling REBUILD_EVENT(). I?m looking forward to hearing from others to learn how and when this rebuilding technique is used.

    Regarding SET_LENGTH_ARRAY():

    When you declare an array without initializing it,
    VOLATILE INTEGER nLightBtns[nMaxLights]

    you?re only telling the system that you want to reserve X amount of memory. My understanding of arrays that haven?t been initialized is that the value of each element is undetermined (it will be whatever that chunk of memory happens to be.) I think Netlinx may automatically set each element to 0 for us but the length of that array is 0 and therefore ?doesn?t really exist.?

    If you do direct assignment like this:

    nLightBtns = ?2,4,6?
    then the length is automatically set to 3.

    If you then did:
    nLightBtns[4] = ?8?
    then the value of the 4th element will indeed be 8 but the length will still be 3 because altering individual elements of an array doesn?t alter the length of the array. If we want to assign values to individual elements of an array and have the length altered then we need to do it manually by calling SET_LENGTH_ARRAY()

    And that?s the problem that the original poster had. The individual elements were getting set but the length of the array was still at 0 so when REBUILD_EVENT() was called nothing was added to the event table.

    Reading over what I wrote about SET_LENGTH_ARRAY() sounds wordy to me and probably didn?t help clear up any confusion. Maybe someone else can put it in more succinct terms.
  • viningvining X Member Posts: 4,353
    Joe Hebert wrote:
    When you declare an array without initializing it,
    VOLATILE INTEGER nLightBtns[nMaxLights]

    you?re only telling the system that you want to reserve X amount of memory. My understanding of arrays that haven?t been initialized is that the value of each element is undetermined (it will be whatever that chunk of memory happens to be.) I think Netlinx may automatically set each element to 0 for us but the length of that array is 0 and therefore ?doesn?t really exist.?
    I basically did just this in this module I recently posted:

    http://amxforums.com/showthread.php?p=25830#post25830

    where;
    VOLATILE INTEGER nEPCII_ActiveTPArry[EPCII_NUM_TPs] ;

    was declared in the variable section and no initial values were set at in the declaration on in start up. First I think your saying that when the elements are not initialized w/ a value they may have the value of what was in that memory location or be set to zero. This could use some clarification cuz if it's not initially set to zero I have some code that needs changing, from what I've seen it appears to be. Anyway if I go into debug and look at the array I see zeros in each element but I see the entire array initialized w/ zeros. When I set the values of these elements and run for loops to check the values of these elements it all works fine. So to me the array lenght is as declared even though it wasn't initilized w/ values.

    So this shouldn't be working for me? And I should be using Rebuild_Event.
  • yuriyuri Junior Member Posts: 861
    vining wrote: »
    And I should be using Rebuild_Event.

    REBUILD_EVENT only has something to do with arrays that you use in the DEFINE_EVENT section.

    the only reason i could find to do this is the following:

    For example, you have a very large project with alot of buttons on a lot of touchpanels. You use a FOR() loop to fill an array (because you are too lazy to type 300+ numbers in Netlinx Studio), and then use REBUILD_EVENT to have that array triggered in DEFINE_EVENT. right?
  • GSLogicGSLogic Original Member Posts: 562
    Thanks for all the post, I think I need to experiment with REBUILD_EVENT().

    What I would like to see is:
    When building a module - say for thermostats and you set the max number of stats to 8.
    You now have your structures/arrays set to 8 which are locked in the module.
    I would like to be able to input 3 stats and than REBUILD the structures/arrays to only include 3 stats. This would help cut down on all the request being sent to the stats and maintain a smaller file size.
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    vining wrote:
    First I think your saying that when the elements are not initialized w/ a value they may have the value of what was in that memory location or be set to zero. This could use some clarification cuz if it's not initially set to zero I have some code that needs changing, from what I've seen it appears to be.
    Netlinx may indeed automagically set the values to 0 for global variables but I know for a fact that that?s not the case for uninitialized arrays in a function as shown when you press button 3 for the code posted below. I like to error on the safe side and assume all uninitialized arrays are uninitialized and if I want to assure values of 0 I?ll plug them in myself.
    wrote:
    Anyway if I go into debug and look at the array I see zeros in each element but I see the entire array initialized w/ zeros. When I set the values of these elements and run for loops to check the values of these elements it all works fine. So to me the array lenght is as declared even though it wasn't initilized w/ values.
    Be default the debugger shows the total length and not the current length. I?m pretty sure it used to be the other way around in older version of NS2. Anyway, right click on the variable and uncheck ?total length? and you?ll see that your array has 0 length.

    I looked at your code and you should be just fine because you?re using the array as a set of flags and you manually peek and poke individual elements. If you have a FOR loop that was based on the LENGTH_ARRAY as shown in the code below for button 1 then you?ll have problems if you don?t set the length someplace.
    DEFINE_DEVICE
    
    dvTP = 10001:1:0
    
    DEFINE_VARIABLE
    
    INTEGER nTestArray1[4]
    
    INTEGER nTestArray2[4] = {1,2,3,4}
    
    DEFINE_FUNCTION fnArrayTest() {
    
       INTEGER x
       INTEGER nTestArray3[4]
       
       SET_LENGTH_ARRAY(nTestArray3,4)
       SEND_STRING 0, "'Printing Uninitialized Array in Function'"
       
       FOR (x=1; x<=LENGTH_ARRAY(nTestArray3); x++) {
          SEND_STRING 0, "'nTestArray3[x]=',ITOA(nTestArray3[x])"
       }
       
    }
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,1] {
    
       PUSH: {
    
          INTEGER x
          
          SEND_STRING 0, "'Printing Uninitialized Array'"
          
          FOR (x=1; x<=LENGTH_ARRAY(nTestArray1); x++) {
    	 SEND_STRING 0, "'nTestArray1[x]=',ITOA(nTestArray1[x])"
          }
       }
    }
    
    BUTTON_EVENT[dvTP,2] {
    
       PUSH: {
    
          INTEGER x
          
          SEND_STRING 0, "'Printing Iinitialized Array'"
          
          FOR (x=1; x<=LENGTH_ARRAY(nTestArray2); x++) {
    	 SEND_STRING 0, "'nTestArray2[x]=',ITOA(nTestArray2[x])"
          }
       }
    }
    
    BUTTON_EVENT[dvTP,3] {
    
       PUSH: {
          fnArrayTest()
       }
    }
    

    Output when button 1 is pushed:
    Line 1 :: Printing Uninitialized Array - 11:42:59

    Output when button 2 is pushed:
    Line 2 :: Printing Iinitialized Array - 11:43:01
    Line 3 :: nTestArray2[x]=1 - 11:43:01
    Line 4 :: nTestArray2[x]=2 - 11:43:01
    Line 5 :: nTestArray2[x]=3 - 11:43:01
    Line 6 :: nTestArray2[x]=4 - 11:43:01

    Output when button 3 is pushed:
    Line 7 :: Printing Uninitialized Array in Function - 11:43:06
    Line 8 :: nTestArray3[x]=7423 - 11:43:06
    Line 9 :: nTestArray3[x]=512 - 11:43:06
    Line 10 :: nTestArray3[x]=2560 - 11:43:06
    Line 11 :: nTestArray3[x]=33831 - 11:43:06
  • viningvining X Member Posts: 4,353
    Joe Hebert wrote:
    Anyway, right click on the variable and uncheck ?total length? and you?ll see that your array has 0 length
    Well, that's new one!

    I guess I do have vague recollections from previous post that declared variables that aren't initialized w/ values may hold the garbage held over from that locatons previous usage so as a precautionary discipline they should be initialized with a value of zero if other values aren't required at start up.

    I'll have to play around with this when I get some time and make sense of it all. If I had used length_array in my for loops instead of the constant I would have seen this and its odd cuz that's normally what I do. I almost always initialize w/ values and use length_array in my loops.

    Thanks Joe!
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    Sure thing vining. I'm always happy to help.
  • viningvining X Member Posts: 4,353
    Just to verify proper application of this command!

    The original code:
    volatile integer HVAC_Temperature[64] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;                                         
        volatile integer HVAC_HeadevTPVStatArrayoint[64]   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;                                        
        volatile integer HVAC_CoolPoint[64]   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
        volatile sinteger HVAC_OutDoor[64]    = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
        volatile integer HVAC_Humidity[64]    = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;                                        
        volatile integer HVAC_HSedevTPVStatArrayoint[64]   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
        volatile integer HVAC_DeHSedevTPVStatArrayoint[64] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;                                       
        volatile integer HVAC_Lock_Stat[64]   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
        volatile integer HVAC_Hold_State[64]  = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
        volatile integer HVAC_Fan_State[64]   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
        volatile integer HVAC_FMode_State[64] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;                                            
        volatile integer HVAC_Mode_State[64]  = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
    

    I needed to add more arrays and since my number of T-Stat will never be 64 I figured this would be a good place to use this command. I've used it in several module but must admit I still don't fully grasp the concept.

    So I replaced the above w/:
    DEFINE_VARIABLE  //Original Arrays  plus new arrays	  
    
    volatile integer HVAC_Temperature[HVAC_ZONES];                                       
    volatile integer HVAC_HeadevTPVStatArrayoint[HVAC_ZONES] ;                                      
    volatile integer HVAC_CoolPoint[HVAC_ZONES]  ;
    volatile sinteger HVAC_OutDoor[HVAC_ZONES]  ;
    volatile integer HVAC_Humidity[HVAC_ZONES] ;                                    
    volatile integer HVAC_HSedevTPVStatArrayoint[HVAC_ZONES] ;
    volatile integer HVAC_DeHSedevTPVStatArrayoint[HVAC_ZONES] ;                               
    volatile integer HVAC_Lock_Stat[HVAC_ZONES] ;
    volatile integer HVAC_Hold_State[HVAC_ZONES] ;
    volatile integer HVAC_Fan_State[HVAC_ZONES] ;
    volatile integer HVAC_FMode_State[HVAC_ZONES] ;                                         
    volatile integer HVAC_Mode_State[HVAC_ZONES] ;
    volatile integer HVAC_G[HVAC_ZONES]  ;
    volatile integer HVAC_Y1[HVAC_ZONES]  ;
    volatile integer HVAC_W1[HVAC_ZONES]  ;
    volatile integer HVAC_W2[HVAC_ZONES]  ;
    volatile integer HVAC_Y2[HVAC_ZONES]  ;
    volatile integer HVAC_O[HVAC_ZONES]  ;
    volatile integer HVAC_B[HVAC_ZONES]  ;
    
    DEFINE_START //INITIALIZE ARRAYS
    
         {
         STACK_VAR INTEGER i ;
         
         for(i=1 ; i <=HVAC_ZONES ; i++)
    	  {
    	  HVAC_Temperature[i] = 0 ;
    	  HVAC_HeadevTPVStatArrayoint[i] = 0 ;
    	  HVAC_CoolPoint[i] = 0 ;
    	  HVAC_OutDoor[i] = 0 ;
    	  HVAC_Humidity[i] = 0 ;
    	  HVAC_HSedevTPVStatArrayoint[i] = 0 ;
    	  HVAC_DeHSedevTPVStatArrayoint[i] = 0 ;
    	  HVAC_Lock_Stat[i] = 0 ;
    	  HVAC_Hold_State[i] = 0 ;
    	  HVAC_Fan_State[i] = 0 ;
    	  HVAC_FMode_State[i] = 0 ;
    	  HVAC_Mode_State[i] = 0 ;
    	  HVAC_G[i] = 0 ;
    	  HVAC_Y1[i] = 0 ;
    	  HVAC_W1[i] = 0 ;
    	  HVAC_W2[i] = 0 ;
    	  HVAC_Y2[i] = 0 ;
    	  HVAC_O[i] = 0 ;
    	  HVAC_B[i] = 0 ;
    	  }
         SET_LENGTH_ARRAY(HVAC_Temperature,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_HeadevTPVStatArrayoint,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_CoolPoint,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_OutDoor,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_Humidity,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_HSedevTPVStatArrayoint,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_DeHSedevTPVStatArrayoint,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_Lock_Stat,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_Hold_State,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_Fan_State,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_FMode_State,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_Mode_State,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_G,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_Y1,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_W1,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_W2,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_Y2,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_O,HVAC_ZONES) ;
         SET_LENGTH_ARRAY(HVAC_B,HVAC_ZONES) ;
         REBUILD_EVENT() ;
         }
    

    From what I gather this should be correct since Rebuild_Event will affect all changed variables above the point where it's declares in it's block of code.

    For those that know is this application correct?
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    vining wrote: »
    From what I gather this should be correct since Rebuild_Event will affect all changed variables above the point where it's declares in it's block of code.

    For those that know is this application correct?
    There is nothing in the code you posted that indicates you need to use REBUILD_EVENT(). It looks to me like you have a bunch of arrays that have nothing to do with BUTTON_EVENTs or anything that affects the event table. Why do you feel you need to use REBUILD_EVENT()?
  • viningvining X Member Posts: 4,353
    Joe Hebert wrote:
    Why do you feel you need to use REBUILD_EVENT()?

    Ok, I understand what you're saying. This command only applies to vars or var arrays that deal w/ event tables and since none of these arrays are BtnArrys, VTArrys or LVLArrys which are used wtih a DEV to create a button_event, level_event, channel_event or timeline_event its use is not required. Basical just as the the instructions say. Maybe if I read it a few more times it will sink in!

    That makes it a little clearer. I guess the whole event table thing and how it works or what it actually is since we can't look at it, is kind of a mystery and a difficult concept to grasp since we rarely deal with it directly. If it wasn't for the few times the limitations of the event tables screwed me or shoulod I say I screwed myself because I wasn't aware of their limitations I wouldn't even know they exist or pay them any mind.

    Another question. In this instance should I even bother with the SET_LENGHT_ARRAY since it's declared with the same lenght in DEFINE_VARIABLE but not populated with initial values? This stuff still boggles my mind.
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    vining wrote: »
    Another question. In this instance should I even bother with the SET_LENGHT_ARRAY since it's declared with the same lenght in DEFINE_VARIABLE but not populated with initial values?
    If you don?t use SET_LENGTH_ARRAY in your instance then the lengths will all be zero. Whether or not a zero length matters is up to you. If you?re using the arrays just for peeking and poking individual values (which the variable names seem to indicate) then you probably don?t care if the length is set or not.
  • viningvining X Member Posts: 4,353
    So what you 're saying is, if I'm just going to check on individual values with in the array from time to time and never make any references to its lenght using length_array(array) for instance then I don't need to define its lenght with set_lenght_array(array,lenght). Now if I don't set the length in this instance couldn't I always return the lenght of the array using max_lenght_array in this situation?

    Normally I would always initiate the array with zero's or actual values when defining it so this has never really been an issue for me but in reading recent post I've been trynig new ideas, second guessing myself and trying understand things that were always sort of fuzzy. Actually most things are still fuzzy!
  • DHawthorneDHawthorne Junior Member Posts: 4,584
    Joe Hebert wrote: »
    If you don?t use SET_LENGTH_ARRAY in your instance then the lengths will all be zero. Whether or not a zero length matters is up to you. If you?re using the arrays just for peeking and poking individual values (which the variable names seem to indicate) then you probably don?t care if the length is set or not.

    Whenever you do a string operation on an array that changes it, the length is also set. So your LEFT_STRING, MID_STRING, etc., will set the length of the array they change. This is also true of assignments - any time you assign a value to an entire array (not just a single element), the length is set then too. It's possible that any internal NetLinx function that operates on an array as a whole and changes it will set the length, but these are the cases it does I am sure about.
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    vining wrote:
    Now if I don't set the length in this instance couldn't I always return the lenght of the array using max_lenght_array in this situation?
    You can call the function if you want but you already know the answer. In this situation I?d use the constant you have in place - HVAC_ZONES.
Sign In or Register to comment.