General scripting advice
Posted: Sun Jun 05, 2022 10:13 pm
I'm totally new to Moho scripting, I would appreciate some general advice on scripting, in particular what development environment you set up.
1. Do you install a seperate LUA distribution where you develop the non- moho specific parts of your code? I personally didn't see the point of this as everything is so closely tied to the Moho api?
2. Do you set up a test rig within Moho? What exactly does it consist of?
3. When you start a new script do you use an existing one and modify it or do you start from scratch, or from a skeleton script?
4. A lot of lines of code go into building the GUI. Do you use any script tools to build the GUI or do you feel its better to just script it yourself everytime?
5. How do you handle version control? When developing I'm guessing you cant just change the lua file name as the internal moho table names will clash in the script menu with older version of your script? Every time I make a change that I worry might break an existing working version (which as a beginner is all the time), I end up duplicating the original file and changing the extension name of the original to hide it from moho, so it doesn't clash with the new test version which I am about to save. The other way is to handle version control within your own script by commenting out chunks of code as backup when you make changes.. nightmare. There must be better ways.
6. Are there any debugging tools (other than the reliable print statement) or advice? Is there a quick way to pause execution and dump all the variable to screen for example, ie setting a break point?
Any other tips? The three I have learnt the hard way is
1) Ensure you use : for table functions and . for table attributes otherwise you may crash moho
2) Use explicit casting for layer types when you create them otherwise further down the line you may get unexpected behaviour when moho sometimes doesn't recognise what type of layer it is.
3) Remember to add MOHO. prexif when using any moho constants.
Thank you
1. Do you install a seperate LUA distribution where you develop the non- moho specific parts of your code? I personally didn't see the point of this as everything is so closely tied to the Moho api?
2. Do you set up a test rig within Moho? What exactly does it consist of?
3. When you start a new script do you use an existing one and modify it or do you start from scratch, or from a skeleton script?
4. A lot of lines of code go into building the GUI. Do you use any script tools to build the GUI or do you feel its better to just script it yourself everytime?
5. How do you handle version control? When developing I'm guessing you cant just change the lua file name as the internal moho table names will clash in the script menu with older version of your script? Every time I make a change that I worry might break an existing working version (which as a beginner is all the time), I end up duplicating the original file and changing the extension name of the original to hide it from moho, so it doesn't clash with the new test version which I am about to save. The other way is to handle version control within your own script by commenting out chunks of code as backup when you make changes.. nightmare. There must be better ways.
6. Are there any debugging tools (other than the reliable print statement) or advice? Is there a quick way to pause execution and dump all the variable to screen for example, ie setting a break point?
Any other tips? The three I have learnt the hard way is
1) Ensure you use : for table functions and . for table attributes otherwise you may crash moho
2) Use explicit casting for layer types when you create them otherwise further down the line you may get unexpected behaviour when moho sometimes doesn't recognise what type of layer it is.
3) Remember to add MOHO. prexif when using any moho constants.
Thank you