IMPORTANT INFORMATION (EDIT)
This is in no way a reliable resource.
There are unchecked holes in the code and a number of deficiencies. The purpose of this resource is to get you started on trying to make sense of get/setfenv, but you should not directly use this model outside of a learning instrument for picking apart. The script example is also not at all a good set up. There is a low chance I will update this resource until I myself do a little bit more researching on environments. Proceed at your own risk.
You will most likely not have any reason to use get/setfenv. I know I don’t. I made a model anyway and I open-sourced it some time back. I’m bringing it to the DevForum because I want to have a post in Community Resources and I feel like sharing this. Also in that respect, if you ever find yourself needing to use either get/setfenv, you have this which you can read, salvage or do whatever you want. You could even make a framework or system set up in this fashion.
No, that isn’t really API. It’s a script I created after referencing what SyncAdmin did to have their commands work. In their plugins (commands, both ones that come with the model and ones that you can write), you can use certain methods off of “SyncAPI”. It gives a blue underline because it’s like an unknown global variable in-script, but methods actually work because SyncAPI is defined via setfenv in a private-source module.
^ Without setfenv, that normally wouldn’t work.
Leave feedback, comments or whatever below. Feel free to message me if you notice something off about my code as well - I am still learning and far from having a good arsenal of scripting knowledge and power.