Module Management

In this post, I’m going to try and plan out my module layout. As it currently stands I’m only using Squares.py and GUI2.py. This is going to become something quite different, as I’m hoping to solve the namespace issue I’ve been having.

It started when I started using the popular if __name__ == ‘main’: format I decided I wanted to clean up all the initialization stuff into a particular function init()but that was not as easy as I had hoped for. In fact it broke my code enough that I am writing a post about it.

The issue is probably obvious to anyone but me, but I forgot how namespaces worked. That is, I forgot that even if you put a function in the top level of a module, all variables created therein are scoped to that function. So what that left me with, was a global scope that was free of any variable I had created in the init() function. So I took to reddit, as usual, to solve all my issues.

Luckily, the ever present user, eryksun, was around, along with others, and informed me that multiprocessing worked best with the Queue module and my two modules split up into smaller ones.

I figure that that would my scope issue because instead of just calling player.name() for example to get his name, I could call objects.player.name() and get it, from any module that has imported objects. So this is going to mean for my code a slight rewrite, but more of a copy and paste sort of deal, with several changes to most calls in my entire two modules. Which aren’t that big, keep in mind. Maybe 1500 lines total, across Squares.py and GUI2.py.

Anyways, so far, my draft is this:

–          Main, which creates the two threads for logic and GUI2, which I’m going to drop the 2 from.

  • GUI is just going to be fed stats from logic and stats, but will also be able to change some of the stats it changes. I’m not sure how to do this just yet. I’m hoping someone will drop down from the heavens and show me.
  • Logic is going to be the main game logic behind most of everything. It’s going to draw on Tools, Objects, Items, Environment, and Stats so it’s going to import a few things.
    • Tools is going to be the module for most of the my math oriented stuff, also the function for handling images.
    • Objects is going to be the module for all the characters in the game. It will rely on AI for the NPCs. Have to decide whether the character components will be created there or not.
      • AI will be in charge of the AI patterns and such, when they get developed. Like I have previously written, I cannot get a handle on A* pathfinding. I’ve really tried though, it’s just not working.
    • Items is going to handle the items in the game. So all the drops and crap will be taken care of here.
    • Environment is will be where of the world information will be handled, so the world squares, backgrounds, that sort of thing.
    • Stats is going to be where the absolute plethora of statistics will be handled. This game will have an insane amount of stats, let me tell you what.

So there you go, a quick breakdown of what I’ve got in the works for now. It’s been a fun ride so far, for the most part. I hope it keeps going.

Looks like wordpress ate my formatting from msword which is a shame. I had all the module names styled as code.

Leave a Reply

Your email address will not be published.