Still struggling with namespaces

Hey there,

I may be understanding the namespaces thing all wrong.

So I read in another post on this topic that namespaces help avoid dependencies e.g, combat not depending on movement. However in our scripts we are using RPG.Movement in our RPG.Combat namespace so combat is dependent on movement no?



It just helps making things clearer, since you cannot just call on a method from one to another without having to use the namespace. That’s all

1 Like

There will always be dependencies. For example, RPG.Control depends on both RPG.Movement and RPG.Combat. What namespaces help us do is avoid cross dependencies… for example: RPG.Combat relies on RPG.Combat, because the Fighter needs to move the character to the target before attacking. RPG.Movement, on the other hand, does not depend on RPG.Combat, nor should it.

The primary function of namespaces is code organization. It also comes with a healthy dose of optimization. If you don’t need anything in RPG.Combat in your script, you don’t include it, and the compiler knows not to include dependency information in that class’s code.

There is an even further step that can be taken by using Assembly Definitions. Assembly Definions take everything in the folder they reside in and all of it’s subfolders and puts them in a different assembly. This requires not only including the namespace of your classes, but editing the Assembly Definition to link to the Assembly Definition that contains the class you’re after. It’s quite a bit more complex than what we’re doing here, but at some point, I will write a full tutorial on using them as a tool to completely eliminate cross-dependencies, and to make your code more modular in nature.

1 Like