Home AMX User Forum NetLinx Studio

Multi dimensional DEV Array?

Hey just wondering if it is possible to create a multi-dimensional DEV array. In my DEFINE_VARIABLE section I usually do this:
VOLATILE
DEV dvMRA_SOURCES[] = {dvDSS1,dvDSS2,vdvKSCAPE}

but I would like to add another dimension to it, just not sure how to do it or if it is possible

VOLATILE
DEV dvMRA_SOURCES[nROOM1][] = {dvDSS1,dvDSS2,vdvKSCAPE}

Comments

  • DHawthorneDHawthorne Posts: 4,584
    I'm not 100% positive, but I think you can only do multidimensional arrays on intrinsic variable types, and DEVs are a STRUCT. That said, I've never even tried because I think it would be far too difficult to figure out at a glance what is going on in the code.
  • trobertstroberts Posts: 228
    Thanks Dave,
    I was starting to think that too. I just wrote a function to accomplish what I was wanting to do...I think it will work fine. But if someone knows how or if its possible to do a multi dimensional DEV array, please let us know.
    Thanks
  • the8thstthe8thst Posts: 470
    I'd suggest looking into structures.

    I'll expand on your example just a little bit.
    DEFINE_TYPE
    	struct _source {
    		char name[20]
    		dev device
    	}
    	
    	struct _room {
    		char roomName[20]
    		integer numSources
    		_source source[10]
    	}
    DEFINE_CONSTANT
    	integer maxRooms = 3
    
    DEFINE_VARIABLE
    	_room myRooms[maxRooms]
    
    DEFINE_START
    	wait 30 {
    		myRooms[1].roomName = 'Room 1'
    		myRooms[1].numSources = 3
    		myRooms[1].source[1].name 	= 'Sat 1'
    		myRooms[1].source[1].device = dvDSS1
    		myRooms[1].source[2].name 	= 'Sat 2'
    		myRooms[1].source[2].device = dvDSS2
    		myRooms[1].source[3].name	= 'KScape'
    		myRooms[1].source[3].device =  vdvKScape
    		
    		myRooms[2].roomName = 'Room 2'
    		myRooms[2].numSources = 4
    		myRooms[2].source[1].name 	= 'Sat 1'
    		myRooms[2].source[1].device = dvDSS1
    		myRooms[2].source[2].name 	= 'Bluray'
    		myRooms[2].source[2].device = dvBluray
    		myRooms[2].source[3].name	= 'KScape'
    		myRooms[2].source[3].device =  vdvKScape2
    		myRooms[2].source[4].name	= 'XBox'
    		myRooms[2].source[4].device = dvNullDevice // No Control of XBox
    		
    		myRooms[3].roomName = 'Room 1'
    		myRooms[3].numSources = 2
    		myRooms[3].source[1].name 	= 'Sat 1'
    		myRooms[3].source[1].device = dvDSS1
    		myRooms[3].source[2].name 	= 'Apple TV'
    		myRooms[3].source[2].device = dvAppleTV
    	}
    
    DEFINE_EVENT
    
    	data_event[dvNullDevice]
    	{
    		online: {
    			// send room info to touchpanel
    			stack_var integer idx,idx2
    			
    			for(idx = maxRooms; idx; idx--) {
    				// Send Room Name to Addresses 1,2,3
    				send_command data.device,"'!T',idx,myRooms[idx].roomName"
    				for(idx2 = myRooms[idx].numSources; idx2; idx2--) {
    					// Send Room 1 Source Names to Addresses 11,12,13
    					// Send Room 2 Source Names to Addresses 21,22,23
    					// Send Room 3 Source Names to Addresses 31,32,33
    					send_command data.device,"'!T',(idx * 10 + idx2),myRooms[idx].source[idx2].name"
    				}
    			}
    		}
    	}
    
    This isn't how I would normally set things up, but it follows how you were already storing your room's sources. I normally have a separate structure for my sources with names, control type, audio switch input, video switch input, device definition, and source type. Then I can reference that will a simple index.

    You could do that pretty easily with my example above by moving the sources to their own structure and changing the _rooms structure to put a simple integer availableSources[10] instead of nesting the source structure within it. Then you use the room integer array as pointers to the source structure.

    There are thousands of ways to structure your data and I have shown you only two, but I will say learning and living by structures makes code more modular and easier to read for me.
  • trobertstroberts Posts: 228
    Thanks 8th,
    I always use structures as well, but never thought of setting them up for DEVs and sources like that. I likey :)
  • a_riot42a_riot42 Posts: 1,624
    There are some disadvantages with structures, so I use them sparingly. Its hard to believe but you can't pass them to a module, or return them from a function. If you use nested structures, watch execution times increase precipitously as well. I used to use them for storing meta data from servers, but it ended up being so much slower than arrays I gave up.

    You can certainly use multi dimensional arrays of devices. I can see certain applications that that would be very handy. However, its almost always less complex to just store an integer that represents an index to an array of devices but it would depend on the application. If you had a 4x4 wall of TVs you needed to send commands to, you could do something like send_command dvTVs[1][2], "'PowerOn'".
    Paul
Sign In or Register to comment.