Home AMX User Forum NetLinx Studio

Passing Multiple Parameters to Function Help?

First let me say that I really appreciate this community. I've already had several questions answered here and as this is how I am putting food on the table, I thank you. Im somewhat new to AMX so this will likely not be my last newbie-ish question. Heres what Im trying to do.

I have a function that Im using where I want to be able to pass in two char arrays. Im calling the function in two places, but in each of these places I only need to pass one of the char arrays. How do I go about this?
define_function processDebugRequest (cReceivedString[],cConnectionStatus[]) {
	
	if ([vdvDebug,1]) {					
		send_string 0,"'RX$ ClearOne:',cReceivedString" 
	} else if ([vdvDebug,2]) {
		send_string 0,"''"        //I will be doing something here but not now
	} else if ([vdvDebug,3]) {
		send_string 0,"'ClearOne is:',cConnectionStatus"
	} 
}



data_event [dvDevice] {
	string: {
		stack_var 
		char	cReceivedString[100]
	
		cReceivedString = data.text
		processResponse (data.text)
		processDebugRequest (cReceivedString)
	}
	offline: {
		stack_var
		char 	cConnectionStatus[7]
		
		if (deviceInitialized)
			init ()
		processDebugRequest (cConnectionStatus)
		
	}
}


The error Im getting is:
[1] arguments for function (processdebugrequest) taking [2] arguments

Comments

  • jjamesjjames Posts: 2,908
    The thing that differentiates whether or not you want to use cReceivedString or cConnectionStatus is your vdvDebug channel. I would just accept one parameter instead of two.
    define_function processDebugRequest ([color=red]char cMessage[][/color]) {
    	
    	if ([vdvDebug,1]) {					
    		send_string 0,"'RX$ ClearOne:',[color=red]cMessage[/color]" 
    	} else if ([vdvDebug,2]) {
    		send_string 0,"''"        //I will be doing something here but not now
    	} else if ([vdvDebug,3]) {
    		send_string 0,"'ClearOne is:',[color=red]cMessage[/color]"
    	} 
    }
    
    
    
    data_event [dvDevice] {
    	string: {
    		stack_var 
    		char	cReceivedString[100]
    	
    		cReceivedString = data.text
    		processResponse (data.text)
    		processDebugRequest (cReceivedString)
    	}
    	offline: {
    		stack_var
    		char 	cConnectionStatus[7]
    		
    		if (deviceInitialized)
    			init ()
    		processDebugRequest (cConnectionStatus)
    		
    	}
    }
    
  • Ok, well I learned something from that but I also discovered I must be doing something else wrong.

    I want to do stuff based on whether a channel on vdvDebug is on, but not mutually exclusive. Does that make sense? For instance if channel one is on, I want to see cReceivedString info. If channel one AND two are on, I want to see cReceivedString AND cConnectionStatus.

    So, I think the "else if" is the first place I was going wrong with that.
  • rfletcherrfletcher Posts: 217
    If I'm understanding what you want to do correctly, it might be better to make those variables global instead of stack_vars.

    Functions don't permanently maintain copies of their parameters from call to call, so you'd have to pass both parameters in each time you call the function.
    define_variable
    volatile char cReceivedString[100]
    volatile char cConnectionStatus[7]
    
    define_function processDebugRequest () {
    	
    	if ([vdvDebug,1]) {					
    		send_string 0,"'RX$ ClearOne:',cReceivedString" 
    	} else if ([vdvDebug,2]) {
    		send_string 0,"''"        //I will be doing something here but not now
    	} else if ([vdvDebug,3]) {
    		send_string 0,"'ClearOne is:',cConnectionStatus"
    	} 
    }
    
    
    
    data_event [dvDevice] {
    	string: {
    		cReceivedString = data.text
    		processResponse (data.text)
    		processDebugRequest ()
    	}
    	offline: {
    		if (deviceInitialized)
    			init ()
    		processDebugRequest ()
    		
    	}
    }
    

    Hope that's helpful.

    -Ryan
  • Thank you guys! I changed them from stack_var to global variables. Im having to learn from a really complicated (at least to me) program so Im just kinda following the patterns of what was done before me.
Sign In or Register to comment.