I have a custom module to go read and XML and convert it to JSON so I can create a switch grid of buttons. I call the submodule in the main custom module, at the start. It functions properly. However, the switchgrid isn't populating at the start. If I reload the custom module after OSC has already been started, then the switchgrid populates correctly.
I tried placing my function outside of the module.exports, and also inside the module.exports.init() and both resulted in the same.
I'm assuming that my script might be running before the switch is even created so its sending the info no nothing I guess? Is there a correct way to go about this or is it not possible?
You can confirm that is a timing issue wrapping the receive function in a setTimeout().
Another thing you could try is to call the receive function in an app.on("sessionOpened", callback), like so: (check details here: Custom module - Open Stage Control)
Using setTimeout() for some reason escaped my thought process of error checking. That did prove it was a timing issue. And using app.on worked as well, which I like using that better so I went with that option.
Here is a codeclip.io link that will walk you through the code that uses my divisimate file. Click the green Play/Start button, and it'll walk through. Feel free to pause it as it shows the console logs.
Just copy the code to yours, and replace the filePath with your divismate *.dpf file. And you should populate the same results. Note, to replace require to nativeRequire in order to use the npm packages within the custom module.
getPresetInfo() should return an object with the preset name as the key and the preset number as the value. Then use that to populate your switch or button grids. For example: