[Closed] Just a replica
in you case the good way to organize own tools could be (how I would do it):
//** base scripts and one file **//
global MyLibrary =
(
struct MyLibraryStruct
(
MathOps =
(
struct MathOps
(
fn sincos a = [sin a, cos a]
)
),
NodeOps =
(
struct NodeOps
(
fn getName node = if isvalidnode node then node.name else ""
)
)
)
)
//** specific tool and another file **//
global PolyOptimization
(
struct PolyOptimizationStruct
(
private
my_lib = MyLibrary(),
math_ops = my_lib.MathOps(),
node_ops = my_lib.NodeOps(),
public
fn getSceneNodeNames =
(
getname = node_ops.getname
for node in objects collect (getname node)
)
)
global _po = PolyOptimization = PolyOptimizationStruct()
ok
)
/*
_po.getSceneNodeNames()
*/
i create a global variable “_po” just to help myself with easier debugging. you must not use in the code of course.
use some simple and short name… and don’t care if anyone might overwrite it. any commonly used names should not be used as global names anyway. So you shouldn’t be cake about overwriting someone’s else globals
My methods looks little different.
-
I first define structures to create something like namespaces in C# at the beginning.
-
I have only one global MyLibrary.
-
I create only ONE instance of each structure at the beginning of definition.
So my code look like this:( global MyLibrary = ( struct _struct ( MathOps,NodeOps,PolyOptimization ) )() MyLibrary.MathOps = ( struct _struct ( fn sincos a = [sin a, cos a] ) )() MyLibrary.NodeOps = ( struct _struct ( fn getName node = if isvalidnode node then node.name else "" ) )() MyLibrary.PolyOptimization = ( struct _struct ( private math_ops = MyLibrary.MathOps, node_ops = MyLibrary.NodeOps, public fn getSceneNodeNames = ( getname = node_ops.getname for node in objects collect (getname node) ) ) )() ok ) MyLibrary.PolyOptimization.getSceneNodeNames()
I’m actually worry about overriding my own functions :), because some times I will develop several tools for one company with different functionality that may have conflict with each other.
I like this way too. The “namespaces” concept is great, with only one global, and avoiding defining structs inside structs. Very nice. Thanks for sharing.
Another point is I just separated all my tools and functions in two parts: common and specific. common will be updated for all tools which consist of all general functions.
Very instructive topic. Thank you all for sharing your workflows.
I have one small question about DenisT’s script, posted by Miauu.
What is the purpose of defining a local variable like this?
local owner = if owner != undefined do owner
It seems redundant, but probably isn’t, yet I do not understand why.