Home AMX User Forum NetLinx Studio

Copy Array Strangeness

I have 2 arrays, array1[16][3] & array2[16][3]

I'd like to copy array 1 to 2 which I used
array2 = array1
But this does not work.

If I do
for (i=1; i<=16; i++)
{
array2[i] = array1[i]
}
works.

Any idea why one works and not the other. I would assume I could do a straight copy of an array as in the first example.

Comments

  • The first method can only be used for 1-dimensional arrays, according to the NetLinx keywords help file.

    Andy
  • mpullinmpullin Posts: 949
    Do you then have to modify them independent of one another?
  • viningvining Posts: 4,368
    Could make it a structure.
  • mpullinmpullin Posts: 949
    vining wrote: »
    Could make it a structure.
    Yes, that's what I was thinking. But does it actually make a copy during assignment? For instance, if you were to declare a STACK_VAR DEV dvThis_TP, assign it to dvTP1 (a DEV in your DEFINE_DEVICE) and then manipulate one of it's properties (i.e. dvThis_TP.system = 2) will it change the system of the original?

    I've only made copies of structs for legibility purposes, so I'm curious.
  • viningvining Posts: 4,368
    With structs you can do pretty much anything you want.

    Here on a back button I use a stack_var which initializes all elements to 0 or '' to clear a level of a structure before taking the step back:
    if(nLevel > 0 && nLevel <= MAX_UI_Level)
    	  {
    	  STACK_VAR _sLevelList sZeroLevelList ;
    	  STACK_VAR _sLevel sZeroLevel ;
    	  STACK_VAR INTEGER nAllowCompile;//only purpose is to allow this code to complile, otherwise throws an error
    	  
    	  nAllowCompile = 1;//only purpose is to allow this code to complile, otherwise throws an error
    	  sLevelList[nLevel] = sZeroLevelList ;
    	  sLevel[nLevel] = sZeroLevel ;
    	  }
    
    Likewise you can copy one level to another or copy zone data to another.

    Here I create a stack_var of a structure to load parsed data. Once I successfully complete the parsing I transfer the stack to the global structure:
    DEFINE_FUNCTION fnParse_SongInfo(CHAR iCmdParams[][])
    
         {
         STACK_VAR _sPlayList myPlaylist ;
    
                                 ACTIVE(cTag == 'count'):
    				   myPlaylist.nCount = atoi(cStrSeg) ;
    			      ACTIVE(cTag == 'genre'):
    				   myPlaylist.cGenre = cStrSeg ;
    			      ACTIVE(cTag == 'genre_id'):
    				   myPlaylist.cGenre_ID = cStrSeg ;
    			      ACTIVE(cTag == 'coverid'):
    				   myPlaylist.cCoverID = cStrSeg ;
    			      ACTIVE(cTag == 'artist'):
    				   myPlaylist.cArtist = cStrSeg ;
    			      ACTIVE(cTag == 'artist_id'):
    				   myPlaylist.cArtist_ID = cStrSeg ;
    			      ACTIVE(cTag == 'album'):
    				   myPlaylist.cAlbum = cStrSeg ;
    			      ACTIVE(cTag == 'album_id'):
    				   myPlaylist.cAlbum_ID = cStrSeg ;
    			      ACTIVE(cTag == 'title'):
    				   myPlaylist.cTitle = cStrSeg ;
                                 cont.......................
    
    
    
    sSBS.sPlaylist[nIndx] = myPlaylist ;
    

    So you can basically copy the entire structure or just certain segments of the structure as needed as long as the structures or segement of the structures have the same architecture.
Sign In or Register to comment.