Home AMX User Forum NetLinx Studio
Options

Structure Arrays

Is it possible to have a structure array? (Structures within structures.) I can't get it to compile. Grrr - this would be very helpful.

Ex:
STRUCTURE struct_1
{                
	CHAR Name[70] 
	INTEGER Number
}                
STRUCTURE struct_2
{                
	CHAR Name[70] 
	INTEGER Number
}                
STRUCTURE struct_3
{                
	CHAR Name[70] 
	INTEGER Number
}                
STRUCTURE struct_4
{               
	CHAR Name[70]
	INTEGER Number
}

STRUCTURE struct_All[]
{
	 struct_1
	,struct_2
	,struct_3
	,struct_4
}

Perhaps what I'm trying to accomplish is done another way?

Comments

  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Yes you can. Here is an example of the syntax:
    DEFINE_TYPE
    
    STRUCTURE struct_1
    {                
    	CHAR Name[70] 
    	INTEGER Number
    }                
    STRUCTURE struct_2
    {                
    	CHAR Name[70] 
    	INTEGER Number
    }                
    STRUCTURE struct_3
    {                
    	CHAR Name[70] 
    	INTEGER Number
    }                
    STRUCTURE struct_4
    {               
    	CHAR Name[70]
    	INTEGER Number
    }
    
    STRUCTURE struct_All
    {
    	struct_1 somename1
    	struct_2 somename2
    	struct_3 somename3[4]
    	struct_4 somename4
    }
    
    DEFINE_VARIABLE
    
    struct_All	all_structs[5]
    
    
    DEFINE_START
    
    all_structs[1].somename1.Name = 'what'
    
    all_structs[1].somename3[3].Name = 'ever'
    
    jjames wrote:
    Is it possible to have a structure array? (Structures within structures.) I can't get it to compile. Grrr - this would be very helpful.

    Ex:
    STRUCTURE struct_1
    {                
    	CHAR Name[70] 
    	INTEGER Number
    }                
    STRUCTURE struct_2
    {                
    	CHAR Name[70] 
    	INTEGER Number
    }                
    STRUCTURE struct_3
    {                
    	CHAR Name[70] 
    	INTEGER Number
    }                
    STRUCTURE struct_4
    {               
    	CHAR Name[70]
    	INTEGER Number
    }
    
    STRUCTURE struct_All[]
    {
    	 struct_1
    	,struct_2
    	,struct_3
    	,struct_4
    }
    

    Perhaps what I'm trying to accomplish is done another way?
  • Options
    mpullinmpullin Posts: 949
    Structure: can we build it? Yes we can!
  • Options
    jjamesjjames Posts: 2,908
    Thank you much! Works like a charm. :D
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    jjames wrote:
    Thank you much! Works like a charm. :D
    It's magically delicious. :)
  • Options
    GSLogicGSLogic Posts: 562
    jjames wrote:
    Is it possible to have a structure array? (Structures within structures.) I can't get it to compile. Grrr - this would be very helpful.

    You can also have multi dimension arrays inside the structure.
    //**************************
      STRUCTURE _test
      {
         char    strName[4][70];
         integer nNumber[4];
      }
    //***************************
    DEFINE_VARIABLE
       _test test[4]
    
    //***************************
    DEFINE_START
      test[1].strName[1] = 'slot one array one';
      test[1].nNumber[1] = 1;
      
      test[2].strName[3] = 'slot three array two';
      test[2].nNumber[3] = 3;
    

    Just another way to look at it.
  • Options
    jjamesjjames Posts: 2,908
    GSLogic wrote:
    You can also have multi dimension arrays inside the structure.

    Hmmm - I might like this one just a tad better. I can then set up constants instead of trying to remember what test[1] or test[5] is.
  • Options
    dthorsondthorson Posts: 103
    Here is an array of structures. This may be a simple version of what you were looking for. Of course you can have any variable inside CHAR, INT, INT[][].
    PROGRAM_NAME='TestStruct'
    
    DEFINE_TYPE
    STRUCTURE _sStuct_Define
    {
    	CHAR		cVar1[50]	// 
    	CHAR		cVar2[255]	// 
    	CHAR		cVar3[50]	// 
    	INTEGER		iVar1		// 
    	INTEGER		iVar2		// 
    }
    
    DEFINE_VARIABLE
    
    _sStuct_Define struct1
    _sStuct_Define struct2
    _sStuct_Define struct3
    _sStuct_Define struct4
    _sStuct_Define struct5
    
    _sStuct_Define structAll[5]
    
    DEFINE_START
    structAll[1] = struct1
    structAll[2] = struct2
    structAll[3] = struct3
    structAll[4] = struct4
    structAll[5] = struct5
    
Sign In or Register to comment.