How to organize code

Please post any questions about developing your plugin here. Please use the search function before posting!
12jdlovins
Junior Member
Posts: 17
Joined: Mon Apr 16, 2018 5:11 am

How to organize code

Postby 12jdlovins » Tue May 01, 2018 3:30 am

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!
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: How to organize code

Postby satoon101 » Tue May 01, 2018 1:13 pm

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.
Image
12jdlovins
Junior Member
Posts: 17
Joined: Mon Apr 16, 2018 5:11 am

Re: How to organize code

Postby 12jdlovins » Tue May 01, 2018 5:03 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 27 guests