Page 1 of 1

How to organize code

Posted: Tue May 01, 2018 3:30 am
by 12jdlovins
Not sure how to really make that title any better... This isn't really any specific programming questions but more so how to really organize it and format it.

I have a zones plugin i want to make so i start with zones.py and such but say I wanted to add a menu for zoning capabilities but don't want to clutter the zones.py file. I made a file structure such as

Code: Select all

zones/
   zones.py
   core/
      menus/
         triggers.py
         


The issue is triggers.py never gets loaded since i never need to actually import anything from it since i put the SayCommands and such into it, i guess almost like its own plugin. I found that i can use import_module("zones.core.menus.triggers") to force load it but that seems like a hack so maybe I am looking at this wrong.

I could put the SayCommands into zones.py and interact with the triggers.py file so that i would have to import it but seems.. not optimal? I tried looking at the gungame plugin but that is... a lot of confusing stuff going on.

Thanks!

Re: How to organize code

Posted: Tue May 01, 2018 1:13 pm
by satoon101
You don't have to use import_module. Even if you don't need to import anything from that module, you can still just import it normally:

Syntax: Select all

import .core.menus.triggers

Though, I don't really know all of your packages/modules and the functionality of each, so it would be hard to say how I would personally structure this.

Re: How to organize code

Posted: Tue May 01, 2018 5:03 pm
by 12jdlovins
Yeah I could do that i suppose, seems like I'm going about it wrong if i just throw an import statement at it for no other reason then to load it into memory. I'll have to mess around with stuff i guess.