Home AMX User Forum NetLinx Studio
Options

get_last for dev arrays on level events - a solution?

Hi - this works for me after a few runs...but I can't believe it should, given the persistent nature of the "can't do get_last on dev arrays in level events" situation.

I created a function
DEFINE_FUNCTION integer my_get_last(dev adDevArray[], dev dvDevice) {
    integer	iCount;
    integer	iMax;
    
    iCount = 1;
    iMax = length_array(adDevArray);
    while (iCount <= iMax) {
	if (adDevArray[iCount] == dvDevice)
	    return iCount;
	iCount++;
    }
    return 0;
}

then in the level event, I say
LEVEL_EVENT[adTPSurProc, LV_VOLUME] {
    stack_var integer iTP;
    
    iTP = my_get_last(adTPSurProc, level.input.device); 

and it works...feels too easy. Am I going to get bitten with this?

Comments

  • Options
    jjamesjjames Posts: 2,908
    Really?

    GET_LAST doesn't work in LEVEL_EVENTs? I must have missed that conversation, becuase I've been using it just fine.
    LEVEL_EVENT[dv_TP,1]	// LEVEL EVENT FOR ADA VOL CHANGES
    LEVEL_EVENT[dv_TP,2]
    {
    	LOCAL_VAR INTEGER nPANEL			// PANEL NUMBER
    	nPANEL = GET_LAST(dv_TP)			// GET PANEL NUMBER
    
    	IF(PANEL[nPANEL].AUDIO_TYPE = ADA AND !nVOL_LOCK[nPANEL])	// IF PANEL CONTROLS AN ADA SOURCE
    	{
    		IF(TIMELINE_ACTIVE(nPANEL+18))
    			TIMELINE_KILL(nPANEL+18)
    		IF(!nPANEL_INACT[nPANEL])
    			TIMELINE_CREATE(nPANEL+18,lVOL_TIME,2,TIMELINE_RELATIVE,TIMELINE_ONCE)
    	}
    }
    

    Perhaps I'll be the one to get bitten later on, but it's working just fine.
  • Options
    youstrayoustra Posts: 135
    get_last didn't work for me, per technote 486. Does it work sporadically (for your case but not mine) or am I reading this wrong?
  • Options
    jjamesjjames Posts: 2,908
    Interesting . . . after reading the TN, I guess I can see why it's working for me. The TN says:
    When used with a DEVLEV or DEV array, GET_LAST does not work correctly. It should return the number of the array element that triggers the event.
    Instead GET_LAST(<DEVLEV array>) will typically return 0; GET_LAST(<DEV array>) will return the GET_LAST value from the last BUTTON, CHANNEL, or DATA event that used <DEV array>.

    My example code is used for when the level changes of the volume for any of my ADA zones. Well, normally the level doesn't change unless the user specifically changes it (and it's typically from that panel.) I guess my GET_LAST in the LEVEL_EVENT is referencing the GET_LAST in my BUTTON_EVENT that raises or lowers the volume, which would both be the same. So perhaps it's just coincidence that it's "working" for me.

    I don't know for sure what's allowing it to work, but it's worked consistantly for me. I'll run some tests today and report back later.
  • Options
    yuriyuri Posts: 861
    the way i see it, is its like this:
    if you use a devlev and try to get the last sldier that caused an event (just like you would when using GET_LAST on a devchan for lets say your DVD control) its not working.
    I have seen this before, and for me, it just kept returning 1, no matter which slider i used.
  • Options
    Reese JacobsReese Jacobs Posts: 347
    GET_LAST() on DEV Arrays in LEVEL_EVENT

    I can tell you from experience that GET_LAST() does not work with DEV arrays in LEVEL_EVENTs just as the Tech Note indicates. You may sometimes get the correct index using GET_LAST in a LEVEL_EVENT on the DEV array but this would merely be by accident and good fortune.

    The sample routine posted at the start of this thread is in fact an implementation of GET_LAST() that will work on a DEV array in LEVEL_EVENTs. In fact, most people write a similar function to use specifically with LEVEL_EVENTs as their own version of GET_LAST. The value reported for LEVEL.INPUT.DEVICE is the correct value for the LEVEL_EVENT and can therefore be used to search a DEV array for a match to return an index. There is nothing magical about this -- this is as expected and is the only reliable way to do GET_LAST on a DEV array in the level event.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    FYI

    The new features for the NI Series firmware released on Dec 3,2007 (v3.30.371) states:

    *Fixed GET_LAST to work properly with levels for DEV and DEVLEV arrays

    If that got fixed maybe we?ll be able to use TIMELINE arrays in the near future?
  • Options
    jjamesjjames Posts: 2,908
    Joe Hebert wrote:
    If that got fixed maybe we?ll be able to use TIMELINE arrays in the near future?
    Crossing my fingers, but not holding my breath.
Sign In or Register to comment.