inline (non-pre-defined) array?
I'm kind of a newbie with only Programming 1 under my belt...
Can an array be passed as a parameter without first defining the array? I call this in-line. The way I am trying to do it does not work.
Example 1:
DEFINE_CALL 'MakeTies' (integer indexSource, integer indexDisplays[])
{
stack_var integer i
stack_var char cmd[64]
cmd = ''
for (i=1;i<=length_array(indexDisplays);i++) {
// add indexDisplays[i] to the list of outputs on the switch command
cmd = "cmd,' ',itoa(indexDisplays[i])"
}
cmd = "'CI',itoa(indexSource),'O',cmd,'T'" // command format is CI<input>O<outputs>T
// add cmd to the switches outgoing queue to be processed by a timeline
}
To put source 1 on displays 1, 2, 3 and 6, and put source 2 on displays 4 and 5, have the button code something like:
PUSH: {
CALL 'MakeTies' ( 1 , { 1, 2, 3, 6 } )
CALL 'MakeTies' ( 2 , { 4, 5 } )
}
Example 2:
TIMELINE_CREATE (TL_POLL, { 1000 }, 1, TIMELINE_RELATIVE, TIMELINE_REPEAT)
vs
DEFINE_VARIABLE
long TL_POLL_Times[1] = { 1000 }
DEFINE_START
TIMELINE_CREATE (TL_POLL, TL_POLL_Times, 1, TIMELINE_RELATIVE, TIMELINE_REPEAT)
My use case is the first example. I have room preset / macro buttons, and some presets have a source going to as many as 8 displays.
I'd really like to take advantage of the serial-controlled AMX switcher's ability to switch an input to multiple outputs with a single command (CI1O1 2 3 6T) rather than taking a few seconds processing a queue of multiple single switches.
I've tried to create a stack_var integer Displays[4] { 1, 2, 3, 6 } before the call but initializing an array is not allowed outside of DEFINE_VARIABLE
I could create an array and populate it one by one, but I'd rather not. example:
PUSH: {
stack_var integer displays[4]
displays[1] = 1
displays[2] = 2
displays[3] = 3
displays[4] = 6
CALL 'MakeTies' ( 1 , displays )
displays[1] = 4
displays[2] = 5
SET_LENGTH_ARRAY(displays, 2) // since I'm not using the full capacity of the array
CALL 'MakeTies' ( 2 , displays )
}
Is passing an array in-line possible in Netlinx?
Answers
-
The simple answer is no, you can't pass raw integer arrays to functions.
The complicated answer is yes, but not in the form you're thinking. One way of handling it could be to pass the array in as a delimited string (flat array) like
CALL 'MakeTies' (2, '1,2,3,6')and then parse the string inside MakeTies.For the second example I have a function you can use that handles that:
// ID; Timeline ID - Constant // lTime; time in 1/1000th seconds // lRepeat; TRUE = repeat, FALSE = run once DEFINE_FUNCTION INTEGER CreateTimeline (LONG ID, LONG lTime, LONG lRepeat) { LONG arrDelay[1], lDelayTime lDelayTime = TYPE_CAST( lTime ) arrDelay[1] = lDelayTime IF(lRepeat) TIMELINE_CREATE(ID,arrDelay,1,TIMELINE_ABSOLUTE,TIMELINE_REPEAT) ELSE TIMELINE_CREATE(ID,arrDelay,1,TIMELINE_ABSOLUTE,TIMELINE_ONCE) }
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums