Very confused with submodules

So, I have a main module that loads submodules just fine from what I can tell. Basically using the template that Jean created in another post here:

However, I may not understand how to properly trigger functions in the main module, I initially tried just calling the function in the main module from the submodule which didnt work and I somewhat expected that, so I simply sent out an OSC message and that triggered just fine for one of my messages, but the other one, that exists in the exact same custom module, appears to just not trigger anything in the main module.

var someArray = []
var someArray2 = []
var llArray = [];

//My functions are here but i'm not including them because they arent important

module.exports = {

    oscOutFilter: function(data) {
        var {host, port, address, args} = data
		
		console.log("PINNED RESULT: " + address)

        if(address === '/test') {
			//existing code that I have
			
			send(host, port, "/select-location", 0, 0, latLngArray)
			
			return
		}
		else if(address === '/removePin') {
			//existing code that I have
			
			if (//expression) {
				send(host, port, "/select-location", 0, 0, latLngArray)	
				
				return data
			}
			else {
				//existing code that I have
				
				send(host, port, "/select-location", parseFloat(newllArray[0]), parseFloat(newllArray[1]), [])
				
				return data
			}
			
			send(host, port, "/testAddress")
			
			return
		}

        return data
    }
}

Everything in the /test address block works every single time without fail, the removePin block works up until it hits send(). Which doesn't mean it isnt sending out an address, I can see in the debug console that every send() function works as expected both in the if statement and the /testAddress, but for whatever reason they will not trigger anything in the main custom module.

I'm not sure what I'm doing wrong :frowning:

EDIT: One of the other modules that's loaded works just fine from what I can tell, but its the first module of the array, which shouldn't matter because of the init function?

The logic inside

else if(address === '/removePin') {

can't work:

send(host, port, "/testAddress")

is never reached because both branches of the conditional block before lead to a return statement.


Also note that messages sent using send() will not be processed again by the custom module. I'm not sure to fully understand what you're trying to do here:

Oh those returns were something else I thought I had removed them.

My goal is to have a main custom module with submodule that do different things.

For example, one for saving states, one for playing videos, one for file browser stuff etc. Then when an address is sent the main module goes to the submodule and does that functionality, which so far has worked perfectly.

I've only run into an issue when trying to jump back to the main module after processing data in a submodule. Ultimately I can just put the logic of the sub module into the main module if this isn't intended to work as well but it was super strange to see that the initial if statement always triggered the main modules function but the else if never could.

I did also try receive() as well to trigger the in filter but that also didn't seem to work but I think what might work is creating a variable widget and then updating it's value with the information for it to send to the main module.

I just realized that I already had a variable widget that was sending back out.......... hence why my main module was being triggered in the If statement. But what I mentioned does work, the submodule just has to trigger a widget to send the address.