Home AMX User Forum AMX General Discussion

Newbie code question please help!

Can someone please help me decipher this code?

If for example you define this under the constant section.

integer TP_COUNT = 6 // I know this asigns TP_Count to 6


DEV TP[TP_COUNT] = // What is being assigned here? How does
{ // TP and [TP_COUNT] fit together?
TP1,
TP2,
TP3,
TP4,
TP5,
TPW
}

char TP_NAME[TP_COUNT][20] = // In this line of code how does TP_NAME work
{ // with the integer assigned to [TP_COUNT]?
'Kitchen', // Is the [20] the max length of the char string?
'Bedroom',
'Loft',
'Theater',
'Basment',
'WebInterface'
}

Thanks for answering a Newbie question! Any information would be greatly appreciated!

Comments

  • integer TP_COUNT = 6
    
    DEV TP[TP_COUNT] =
        {                            
            TP1,                                                
            TP2,                          
            TP3,                          
            TP4,                        
            TP5,                         
            TPW                        
        }
    

    This system has 6 touchpanels whose device numbers have been declared earlier, and this code aggregates those devices into an array.
    char TP_NAME[TP_COUNT][20] =
        {                                             
            'Kitchen',                             
            'Bedroom',                     
            'Loft',                        
            'Theater',                    
            'Basment',                     
            'WebInterface'                 
        }
    

    This is a 2 dimensional character array, or to put it another way, an array of strings containing up to 20 characters each being the names of the touchpanels.
  • Thanks so much for taking the time to give me an answer. If possible can you give me some more information on what a "two dimension array" is?
  • CT-DallasCT-Dallas Posts: 157
    Keith,
    Think of it like there are two different items being defined here - the number of entries in the array (number of panels or TP_Count), and then how large those entries can be (20 characters). Those are your two dimensions.

    If you are more visual, try this analagy:
    If this was a row of lockers at a school, there would be no more than 20 lockers in each row, and the number of rows would be equal to TP_Count.

    The reason this is defined is for memory allocation. We need to tell the system the maximum size to expect. This will then allocate the proper ammount of memory resources to track this array.
  • Thanks guys I got it.
Sign In or Register to comment.